commit b17e9748fad9efd9f4e51b908831b1d6e02876b4 from: Martin Pieuchot date: Fri Mar 20 15:14:20 2020 UTC Compare pointers against NULL. commit - 90eac7479efe209eac4df46846fb74851d671ef8 commit + b17e9748fad9efd9f4e51b908831b1d6e02876b4 blob - 1b65d4428400d8ada970ac351eadd402bd5f2f60 blob + cd1ea06680981ad7958e3e4aca5e9b28a21bc83e --- arraylist.h +++ arraylist.h @@ -32,7 +32,7 @@ * // enlarges the allocated array as needed; * // list.head may change due to realloc * ARRAYLIST_ADD(x, list); - * if (!x) + * if (x == NULL) * abort(); * *x = random_foo_value; * } blob - 6b81da5097f413165d395437388a92004d74bb2a blob + 5df77cf87ea5fd7b1b3e3d0073f2fa02e5c76edc --- debug.h +++ debug.h @@ -33,7 +33,7 @@ dump_atom(const struct diff_data *left, const struct d { const char *s; - if (!atom) { + if (atom == NULL) { print("NULL atom\n"); return; } blob - a99ba63a9c677f5ece15973291d9a5c5ae3e84dc blob + 25e677acde4b2f4134a80545ab78564c5dbb42c0 --- diff_atomize_text.c +++ diff_atomize_text.c @@ -59,7 +59,7 @@ diff_data_atomize_text_lines(struct diff_data *d) /* Record the found line as diff atom */ ARRAYLIST_ADD(atom, d->atoms); - if (!atom) + if (atom == NULL) return DIFF_RC_ENOMEM; *atom = (struct diff_atom){ blob - 56a2983c1ad2e85915e26f7216896658700a0d40 blob + c2ff26743452e2940ddd5e6fc83094b3f5d169de --- diff_main.c +++ diff_main.c @@ -49,7 +49,7 @@ diff_state_add_chunk(struct diff_state *state, bool so result = &state->temp_result; ARRAYLIST_ADD(chunk, *result); - if (!chunk) + if (chunk == NULL) return NULL; *chunk = (struct diff_chunk) { .solved = solved, @@ -98,7 +98,7 @@ diff_data_init_subsection(struct diff_data *d, struct void diff_data_free(struct diff_data *diff_data) { - if (!diff_data) + if (diff_data == NULL) return; if (diff_data->atoms.allocated) ARRAYLIST_FREE(diff_data->atoms); @@ -159,7 +159,8 @@ diff_run_algo(const struct diff_algo_config *algo_conf ARRAYLIST_FREE(state->temp_result); - if (!algo_config || !algo_config->impl || !state->recursion_depth_left){ + if (algo_config == NULL || !algo_config->impl || + !state->recursion_depth_left) { debug("MAX RECURSION REACHED, just dumping diff chunks\n"); return diff_algo_none(algo_config, state); } @@ -198,7 +199,7 @@ diff_run_algo(const struct diff_algo_config *algo_conf struct diff_chunk *final_c; ARRAYLIST_ADD(final_c, state->result->chunks); - if (!final_c) { + if (final_c == NULL) { rc = DIFF_RC_ENOMEM; goto return_rc; } @@ -236,14 +237,14 @@ diff_main(const struct diff_config *config, struct diff_state state; result = malloc(sizeof(struct diff_result)); - if (!result) + if (result == NULL) return NULL; *result = (struct diff_result){}; diff_data_init_root(&result->left, left_data, left_len); diff_data_init_root(&result->right, right_data, right_len); - if (!config->atomize_func) { + if (config->atomize_func == NULL) { result->rc = DIFF_RC_EINVAL; return result; } @@ -270,7 +271,7 @@ diff_main(const struct diff_config *config, void diff_result_free(struct diff_result *result) { - if (!result) + if (result == NULL) return; diff_data_free(&result->left); diff_data_free(&result->right); blob - 2af135b66a21409f60158b61d17612fdbaf53cb7 blob + cfec82d7353470014c6249bc2c73c7273c40181f --- diff_main.h +++ diff_main.h @@ -65,7 +65,7 @@ ranges_merge(struct range *a, const struct range *b) static inline int range_len(const struct range *r) { - if (!r) + if (r == NULL) return 0; return r->end - r->start; } blob - 3ac0aea1fea278e8b4ac34648f22ee49af9a008c blob + 43229a63cba7d76528b622c7c2cdab6a6a86ed7c --- diff_myers.c +++ diff_myers.c @@ -758,7 +758,7 @@ diff_algo_myers_divide(const struct diff_algo_config * size_t kd_len = max + 1; size_t kd_buf_size = kd_len << 1; int *kd_buf = reallocarray(NULL, kd_buf_size, sizeof(int)); - if (!kd_buf) + if (kd_buf == NULL) return DIFF_RC_ENOMEM; int i; for (i = 0; i < kd_buf_size; i++) @@ -950,7 +950,7 @@ diff_algo_myers(const struct diff_algo_config *algo_co } int *kd_buf = reallocarray(NULL, kd_buf_size, sizeof(int)); - if (!kd_buf) + if (kd_buf == NULL) return DIFF_RC_ENOMEM; int i; for (i = 0; i < kd_buf_size; i++) blob - 5f5769aa7ddcab3c2cb38ad4156cc8e208647fd4 blob + cf447d798c044ec7058121d36ed597b8066a575b --- diff_output.c +++ diff_output.c @@ -114,7 +114,7 @@ diff_plain(FILE *dest, const struct diff_config *diff_ return DIFF_RC_EINVAL; result = diff_main(diff_config, info->left_buffer, left_len, info->right_buffer, right_len); - if (!result) + if (result == NULL) return DIFF_RC_EINVAL; if (result->rc != DIFF_RC_OK) return result->rc; @@ -359,7 +359,7 @@ diff_unidiff(FILE *dest, const struct diff_config *dif return DIFF_RC_EINVAL; result = diff_main(diff_config, info->left_buffer, left_len, info->right_buffer, right_len); - if (!result) + if (result == NULL) return DIFF_RC_EINVAL; if (result->rc != DIFF_RC_OK) return result->rc;