clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name regex.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 -pic-is-pie -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/usr.bin/lex/obj -resource-dir /usr/local/lib/clang/13.0.0 -I . -I /usr/src/usr.bin/lex -D HAVE_CONFIG_H -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.bin/lex/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/usr.bin/lex/regex.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 | #include "flexdef.h" |
27 | |
28 | |
29 | static const char* REGEXP_LINEDIR = "^#line ([[:digit:]]+) \"(.*)\""; |
30 | static const char* REGEXP_BLANK_LINE = "^[[:space:]]*$"; |
31 | |
32 | regex_t regex_linedir; |
33 | regex_t regex_blank_line; |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | bool flex_init_regex(void) |
40 | { |
41 | flex_regcomp(®ex_linedir, REGEXP_LINEDIR, REG_EXTENDED); |
42 | flex_regcomp(®ex_blank_line, REGEXP_BLANK_LINE, REG_EXTENDED); |
43 | |
44 | return true; |
45 | } |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | void flex_regcomp(regex_t *preg, const char *regex, int cflags) |
53 | { |
54 | int err; |
55 | |
56 | memset (preg, 0, sizeof (regex_t)); |
57 | |
58 | if ((err = regcomp (preg, regex, cflags)) != 0) { |
59 | const int errbuf_sz = 200; |
60 | char *errbuf, *rxerr; |
61 | |
62 | errbuf = (char*)malloc(errbuf_sz *sizeof(char)); |
63 | if (!errbuf) |
64 | flexfatal(_("Unable to allocate buffer to report regcomp")); |
65 | rxerr = (char*)malloc(errbuf_sz *sizeof(char)); |
66 | if (!rxerr) |
67 | flexfatal(_("Unable to allocate buffer for regerror")); |
68 | regerror (err, preg, rxerr, errbuf_sz); |
69 | snprintf (errbuf, errbuf_sz, "regcomp for \"%s\" failed: %s", regex, rxerr); |
70 | |
71 | flexfatal (errbuf); |
72 | free(errbuf); |
73 | free(rxerr); |
74 | } |
75 | } |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | char *regmatch_dup (regmatch_t * m, const char *src) |
83 | { |
84 | char *str; |
85 | int len; |
86 | |
87 | if (m == NULL || m->rm_so < 0) |
| |
88 | return NULL; |
89 | len = m->rm_eo - m->rm_so; |
90 | str = (char *) malloc ((len + 1) * sizeof (char)); |
| |
91 | if (!str) |
| |
| |
92 | flexfatal(_("Unable to allocate a copy of the match")); |
93 | strncpy (str, src + m->rm_so, len); |
| 11 | | Null pointer passed as 1st argument to string copy function |
|
94 | str[len] = 0; |
95 | return str; |
96 | } |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | char *regmatch_cpy (regmatch_t * m, char *dest, const char *src) |
105 | { |
106 | if (m == NULL || m->rm_so < 0) { |
107 | if (dest) |
108 | dest[0] = '\0'; |
109 | return dest; |
110 | } |
111 | |
112 | snprintf (dest, regmatch_len(m), "%s", src + m->rm_so); |
113 | return dest; |
114 | } |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | int regmatch_len (regmatch_t * m) |
122 | { |
123 | if (m == NULL || m->rm_so < 0) { |
124 | return 0; |
125 | } |
126 | |
127 | return m->rm_eo - m->rm_so; |
128 | } |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | int regmatch_strtol (regmatch_t * m, const char *src, char **endptr, |
140 | int base) |
141 | { |
142 | int n = 0; |
143 | |
144 | #define bufsz 20 |
145 | char buf[bufsz]; |
146 | char *s; |
147 | |
148 | if (m == NULL || m->rm_so < 0) |
| 1 | Assuming 'm' is not equal to NULL | |
|
| 2 | | Assuming field 'rm_so' is >= 0 | |
|
| |
149 | return 0; |
150 | |
151 | if (regmatch_len (m) < bufsz) |
| 4 | | Assuming the condition is false | |
|
| |
152 | s = regmatch_cpy (m, buf, src); |
153 | else |
154 | s = regmatch_dup (m, src); |
| |
155 | |
156 | n = strtol (s, endptr, base); |
157 | |
158 | if (s != buf) |
159 | free (s); |
160 | |
161 | return n; |
162 | } |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | bool regmatch_empty (regmatch_t * m) |
170 | { |
171 | return (m == NULL || m->rm_so < 0 || m->rm_so == m->rm_eo); |
172 | } |