diff options
author | David Robillard <d@drobilla.net> | 2020-08-13 17:25:55 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-08-13 17:25:55 +0200 |
commit | 59d5056a65062ff2b46bcf477651e71f5d4984e0 (patch) | |
tree | 3ef5c355b26546355deb2f1b5ec8a713692b898c | |
parent | 8e31bb8064f5e2b2e0bfb8e9e6e5f85091e3a8bc (diff) | |
download | zix-59d5056a65062ff2b46bcf477651e71f5d4984e0.tar.gz zix-59d5056a65062ff2b46bcf477651e71f5d4984e0.tar.bz2 zix-59d5056a65062ff2b46bcf477651e71f5d4984e0.zip |
Fix potential null pointer dereferences
-rw-r--r-- | .clang-tidy | 1 | ||||
-rw-r--r-- | wscript | 1 | ||||
-rw-r--r-- | zix/btree.c | 6 | ||||
-rw-r--r-- | zix/trie.c | 11 |
4 files changed, 14 insertions, 5 deletions
diff --git a/.clang-tidy b/.clang-tidy index 17b9b27..84771ad 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,7 +9,6 @@ Checks: > -cert-err34-c, -cert-msc30-c, -cert-msc50-cpp, - -clang-analyzer-core.NullDereference, -cppcoreguidelines-init-variables, -google-readability-casting, -hicpp-multiway-paths-covered, @@ -59,7 +59,6 @@ def configure(conf): '-Wno-cast-align', '-Wno-conversion', '-Wno-inline', - '-Wno-null-dereference', '-Wno-padded', '-Wno-suggest-attribute=const', '-Wno-suggest-attribute=pure', diff --git a/zix/btree.c b/zix/btree.c index dc8f32b..55d6613 100644 --- a/zix/btree.c +++ b/zix/btree.c @@ -593,8 +593,10 @@ zix_btree_remove(ZixBTree* const t, n->children[1]->n_vals}; n = zix_btree_merge(t, n, 0); - ti->stack[ti->level].node = n; - ti->stack[ti->level].index = counts[i]; + if (ti) { + ti->stack[ti->level].node = n; + ti->stack[ti->level].index = counts[i]; + } } else { // Both child's siblings are minimal, merge them if (i < n->n_vals) { @@ -215,7 +215,11 @@ trie_insert_tail(ZixTrieNode** n_ptr, while (first[0]) { assert(zix_trie_node_check(*n_ptr)); - c = realloc_node(NULL, 1); + c = realloc_node(NULL, 1); + if (!c) { + return NULL; + } + c->str = NULL; c->num_children = 0; @@ -225,6 +229,11 @@ trie_insert_tail(ZixTrieNode** n_ptr, ++first; } + + if (!c) { + return NULL; + } + c->num_children = 0; c->str = str; assert(zix_trie_node_check(c)); |