clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name lib_tgoto.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/lib/libcurses/obj -resource-dir /usr/local/llvm16/lib/clang/16 -I . -I /usr/src/lib/libcurses -D _XOPEN_SOURCE_EXTENDED -D NDEBUG -internal-isystem /usr/local/llvm16/lib/clang/16/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libcurses/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/lib/libcurses/tinfo/lib_tgoto.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 | |
36 | #include <curses.priv.h> |
37 | |
38 | #include <ctype.h> |
39 | #include <termcap.h> |
40 | |
41 | MODULE_ID("$Id: lib_tgoto.c,v 1.7 2023/10/17 09:52:09 nicm Exp $") |
42 | |
43 | #if !PURE_TERMINFO |
44 | static bool |
45 | is_termcap(const char *string) |
46 | { |
47 | bool result = TRUE; |
48 | |
49 | if (string == 0 || *string == '\0') { |
50 | result = FALSE; |
51 | } else { |
52 | while ((*string != '\0') && result) { |
53 | if (*string == '%') { |
54 | switch (*++string) { |
55 | case 'p': |
56 | result = FALSE; |
57 | break; |
58 | case '\0': |
59 | string--; |
60 | break; |
61 | } |
62 | } else if (string[0] == '$' && string[1] == '<') { |
63 | result = FALSE; |
64 | } |
65 | string++; |
66 | } |
67 | } |
68 | return result; |
69 | } |
70 | |
71 | static char * |
72 | tgoto_internal(const char *string, int x, int y) |
73 | { |
74 | static char *result; |
75 | static size_t length; |
76 | |
77 | int swap_arg; |
78 | int param[3]; |
79 | size_t used = 0; |
80 | size_t need = 10; |
81 | int *value = param; |
82 | bool need_BC = FALSE; |
83 | |
84 | if (BC) |
| |
| |
85 | need += strlen(BC); |
86 | |
87 | param[0] = y; |
88 | param[1] = x; |
89 | param[2] = 0; |
90 | |
91 | while (*string != 0) { |
| 5 | | Loop condition is true. Entering loop body | |
|
| 18 | | Assuming the condition is true | |
|
| 19 | | Loop condition is true. Entering loop body | |
|
| 34 | | Assuming the condition is false | |
|
| 35 | | Loop condition is false. Execution continues on line 186 | |
|
92 | if ((used + need) > length) { |
| |
| |
93 | length += (used + need); |
94 | if ((result = typeRealloc(char, length, result)) == 0) { |
| 7 | | Assuming the condition is false | |
|
| |
| |
| 22 | | Assuming the condition is false | |
|
| |
95 | length = 0; |
96 | break; |
97 | } |
98 | } |
99 | if (*string == '%') { |
| |
| 24 | | Assuming the condition is true | |
|
| |
100 | const char *fmt = 0; |
101 | |
102 | switch (*++string) { |
| 10 | | Control jumps to 'case 43:' at line 117 | |
|
| 26 | | Control jumps to 'case 46:' at line 120 | |
|
103 | case '\0': |
104 | string--; |
105 | break; |
106 | case 'd': |
107 | fmt = "%d"; |
108 | break; |
109 | case '2': |
110 | fmt = "%02d"; |
111 | *value %= 100; |
112 | break; |
113 | case '3': |
114 | fmt = "%03d"; |
115 | *value %= 1000; |
116 | break; |
117 | case '+': |
118 | *value += UChar(*++string); |
119 | |
120 | case '.': |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | if (*value == 0) { |
| 11 | | Assuming the condition is true | |
|
| |
| 27 | | Assuming the condition is true | |
|
| |
127 | if (BC != 0) { |
| 13 | | Assuming 'BC' is not equal to null | |
|
| |
| 29 | | Assuming 'BC' is equal to null | |
|
| |
128 | *value += 1; |
129 | need_BC = TRUE; |
130 | } else { |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | *value = 0200; |
139 | } |
140 | } |
141 | result[used++] = (char) *value++; |
142 | break; |
143 | case '%': |
144 | result[used++] = *string; |
145 | break; |
146 | case 'r': |
147 | swap_arg = param[0]; |
148 | param[0] = param[1]; |
149 | param[1] = swap_arg; |
150 | break; |
151 | case 'i': |
152 | param[0] += 1; |
153 | param[1] += 1; |
154 | break; |
155 | case '>': |
156 | if (*value > string[1]) |
157 | *value += string[2]; |
158 | string += 2; |
159 | break; |
160 | case 'n': |
161 | param[0] ^= 0140; |
162 | param[1] ^= 0140; |
163 | break; |
164 | case 'B': |
165 | *value = 16 * (*value / 10) + (*value % 10); |
166 | break; |
167 | case 'D': |
168 | *value -= 2 * (*value % 16); |
169 | break; |
170 | } |
171 | if (fmt != 0) { |
| 15 | | Execution continues on line 171 | |
|
| |
| 31 | | Execution continues on line 171 | |
|
| |
172 | _nc_SPRINTF(result + used, _nc_SLIMIT(length - used) |
173 | fmt, *value++); |
174 | used += strlen(result + used); |
175 | fmt = 0; |
176 | } |
177 | if (value - param > 2) { |
| |
| |
178 | value = param + 2; |
179 | *value = 0; |
180 | } |
181 | } else { |
182 | result[used++] = *string; |
183 | } |
184 | string++; |
185 | } |
186 | if (result != 0) { |
| |
187 | if (need_BC) { |
| |
188 | _nc_STRCPY(result + used, BC, length - used); |
| 38 | | Null pointer passed as 2nd argument to string copy function |
|
189 | used += strlen(BC); |
190 | } |
191 | result[used] = '\0'; |
192 | } |
193 | return result; |
194 | } |
195 | #endif |
196 | |
197 | |
198 | |
199 | |
200 | |
201 | NCURSES_EXPORT(char *) |
202 | tgoto(const char *string, int x, int y) |
203 | { |
204 | char *result; |
205 | |
206 | T((T_CALLED("tgoto(%s, %d, %d)"), _nc_visbuf(string), x, y)); |
207 | #if !PURE_TERMINFO |
208 | if (is_termcap(string)) |
| |
209 | result = tgoto_internal(string, x, y); |
| 2 | | Calling 'tgoto_internal' | |
|
210 | else |
211 | #endif |
212 | if ((result = TIPARM_2(string, y, x)) == NULL) { |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | if ((result = TIPARM_1(string, y)) == NULL) { |
220 | result = TIPARM_0(string); |
221 | } |
222 | } |
223 | returnPtr(result); |
224 | } |