clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name tree.c -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 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -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/usr.bin/ctags/obj -resource-dir /usr/local/llvm16/lib/clang/16 -I /usr/src/usr.bin/ctags -internal-isystem /usr/local/llvm16/lib/clang/16/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.bin/ctags/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fcf-protection=branch -fno-jump-tables -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/scan/2024-01-11-140451-98009-1 -x c /usr/src/usr.bin/ctags/tree.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 | #include <err.h> |
| 34 | #include <limits.h> |
| 35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
| 37 | #include <string.h> |
| 38 | #include <sys/dirent.h> |
| 39 | |
| 40 | #include "ctags.h" |
| 41 | |
| 42 | bool in_preload = NO; |
| 43 | |
| 44 | static void add_node(NODE *, NODE *); |
| 45 | static void free_tree(NODE *); |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | void |
| 52 | pfnote(char *name, int ln) |
| 53 | { |
| 54 | NODE *np; |
| 55 | char *fp; |
| 56 | char nbuf[1+MAXNAMLEN+1]; |
| 57 | |
| 58 | if (!(np = malloc(sizeof(NODE)))) { |
| |
| 2 | | Assuming 'np' is non-null | |
|
| 59 | warnx("too many entries to sort"); |
| 60 | put_entries(head); |
| 61 | free_tree(head); |
| 62 | if (!(head = np = malloc(sizeof(NODE)))) |
| 63 | err(1, NULL); |
| 64 | } |
| 65 | if (!xflag && !strcmp(name, "main")) { |
| 3 | | Assuming 'xflag' is not equal to 0 | |
|
| 66 | if (!(fp = strrchr(curfile, '/'))) |
| 67 | fp = curfile; |
| 68 | else |
| 69 | ++fp; |
| 70 | (void)snprintf(nbuf, sizeof nbuf, "M%s", fp); |
| 71 | fp = strrchr(nbuf, '.'); |
| 72 | if (fp && !fp[2]) |
| 73 | *fp = EOS; |
| 74 | name = nbuf; |
| 75 | } |
| 76 | if (!(np->entry = strdup(name))) |
| 4 | | Assuming field 'entry' is non-null | |
|
| |
| 77 | err(1, NULL); |
| 78 | np->file = curfile; |
| 79 | np->lno = ln; |
| 80 | np->left = np->right = 0; |
| 81 | np->been_warned = NO; |
| 82 | np->dynfile = in_preload; |
| 83 | if (!(np->pat = strdup(lbuf))) |
| 6 | | Assuming field 'pat' is non-null | |
|
| |
| 84 | err(1, NULL); |
| 85 | if (!head) |
| 8 | | Assuming 'head' is non-null | |
|
| |
| 86 | head = np; |
| 87 | else |
| 88 | add_node(np, head); |
| 89 | } |
| 10 | | Potential leak of memory pointed to by 'np' |
|
| 90 | |
| 91 | static void |
| 92 | add_node(NODE *node, NODE *cur_node) |
| 93 | { |
| 94 | int dif; |
| 95 | |
| 96 | dif = strcmp(node->entry, cur_node->entry); |
| 97 | if (!dif) { |
| 98 | if (node->file == cur_node->file) { |
| 99 | if (!wflag) |
| 100 | fprintf(stderr, "Duplicate entry in file %s, " |
| 101 | "line %d: %s\nSecond entry ignored\n", |
| 102 | node->file, lineno, node->entry); |
| 103 | return; |
| 104 | } |
| 105 | if (!cur_node->been_warned) |
| 106 | if (!wflag) |
| 107 | fprintf(stderr, "Duplicate entry in files %s " |
| 108 | "and %s: %s (Warning only)\n", |
| 109 | node->file, cur_node->file, node->entry); |
| 110 | cur_node->been_warned = YES; |
| 111 | } |
| 112 | else if (dif < 0) |
| 113 | if (cur_node->left) |
| 114 | add_node(node, cur_node->left); |
| 115 | else |
| 116 | cur_node->left = node; |
| 117 | else if (cur_node->right) |
| 118 | add_node(node, cur_node->right); |
| 119 | else |
| 120 | cur_node->right = node; |
| 121 | } |
| 122 | |
| 123 | static void |
| 124 | free_tree(NODE *node) |
| 125 | { |
| 126 | if (node) { |
| 127 | free_tree(node->left); |
| 128 | free_tree(node->right); |
| 129 | |
| 130 | free(node->entry); |
| 131 | free(node->pat); |
| 132 | if (node->dynfile == YES) |
| 133 | free(node->file); |
| 134 | free(node); |
| 135 | } |
| 136 | } |