diff --git a/infer/tests/codetoanalyze/c/errors/issues.exp b/infer/tests/codetoanalyze/c/errors/issues.exp index 8b5013eb7..56c6b0d16 100644 --- a/infer/tests/codetoanalyze/c/errors/issues.exp +++ b/infer/tests/codetoanalyze/c/errors/issues.exp @@ -72,6 +72,9 @@ codetoanalyze/c/errors/null_dereference/getc.c, crash_ungetc, 5, NULL_DEREFERENC codetoanalyze/c/errors/null_dereference/getc.c, crash_ungetc, 5, RETURN_VALUE_IGNORED codetoanalyze/c/errors/null_dereference/getc.c, crash_vfprintf, 5, NULL_DEREFERENCE codetoanalyze/c/errors/null_dereference/getc.c, nocrash_ungetc, 5, RETURN_VALUE_IGNORED +codetoanalyze/c/errors/null_dereference/issue_680.c, null_ptr_deref2_bad, 0, NULL_DEREFERENCE +codetoanalyze/c/errors/null_dereference/issue_680.c, null_ptr_deref_bad, 0, NULL_DEREFERENCE +codetoanalyze/c/errors/null_dereference/issue_680.c, null_ptr_deref_bad_FN, 0, PRECONDITION_NOT_MET codetoanalyze/c/errors/null_dereference/malloc_no_null_check.c, test_malloc, 2, NULL_DEREFERENCE codetoanalyze/c/errors/null_dereference/memcpy-test.c, testError1, 3, NULL_DEREFERENCE codetoanalyze/c/errors/null_dereference/memcpy-test.c, testError2, 5, NULL_DEREFERENCE diff --git a/infer/tests/codetoanalyze/c/errors/null_dereference/issue_680.c b/infer/tests/codetoanalyze/c/errors/null_dereference/issue_680.c new file mode 100644 index 000000000..6b2bed226 --- /dev/null +++ b/infer/tests/codetoanalyze/c/errors/null_dereference/issue_680.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#include + +struct list { + struct list* next; +}; + +void go_to_next(struct list* head) { + if (head->next != NULL) { + head = head->next; + } +} + +void null_ptr_deref_bad() { go_to_next(NULL); } + +void go_to_end_of_list(struct list* head) { + while (head->next != NULL) { + head = head->next; + } +} + +void null_ptr_deref_bad_FN() { go_to_end_of_list(NULL); } + +void check_next(struct list* head) { + while (head->next != NULL) { + whatever(); + } +} + +void null_ptr_deref2_bad() { check_next(NULL); }