clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name lsearch.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/lib/libc/obj -resource-dir /usr/local/lib/clang/13.0.0 -include namespace.h -I /usr/src/lib/libc/include -I /usr/src/lib/libc/hidden -D __LIBC__ -D APIWARN -D YP -I /usr/src/lib/libc/yp -I /usr/src/lib/libc -I /usr/src/lib/libc/gdtoa -I /usr/src/lib/libc/arch/amd64/gdtoa -D INFNAN_CHECK -D MULTIPLE_THREADS -D NO_FENV_H -D USE_LOCALE -I /usr/src/lib/libc -I /usr/src/lib/libc/citrus -D RESOLVSORT -D FLOATING_POINT -D PRINTF_WIDE_CHAR -D SCANF_WIDE_CHAR -D FUTEX -D PIC -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libc/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/lib/libc/stdlib/lsearch.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | #include <sys/types.h> |
| 36 | #include <string.h> |
| 37 | #include <search.h> |
| 38 | |
| 39 | typedef int (*cmp_fn_t)(const void *, const void *); |
| 40 | |
| 41 | void * |
| 42 | lsearch(const void *key, void *base, size_t *nelp, size_t width, |
| 43 | cmp_fn_t compar) |
| 44 | { |
| 45 | void *element = lfind(key, base, nelp, width, compar); |
| |
| |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | if (element == NULL) { |
| 7 | | Assuming 'element' is equal to NULL | |
|
| |
| 52 | element = memmove((char *)base + *nelp * width, key, width); |
| 9 | | Null pointer passed as 1st argument to memory copy function |
|
| 53 | *nelp += 1; |
| 54 | } |
| 55 | return element; |
| 56 | } |
| 57 | |
| 58 | void * |
| 59 | lfind(const void *key, const void *base, size_t *nelp, size_t width, |
| 60 | cmp_fn_t compar) |
| 61 | { |
| 62 | const char *element, *end; |
| 63 | |
| 64 | end = (const char *)base + *nelp * width; |
| 65 | for (element = base; element < end; element += width) |
| 2 | | Assuming 'element' is < 'end' | |
|
| 3 | | Loop condition is true. Entering loop body | |
|
| 66 | if (!compar(key, element)) |
| 4 | | Assuming the condition is true | |
|
| |
| 67 | return((void *)element); |
| 68 | return NULL; |
| 69 | } |
| 70 | DEF_WEAK(lfind); |