clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name display.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/gnu/usr.bin/texinfo/obj/info -resource-dir /usr/local/lib/clang/13.0.0 -D HAVE_CONFIG_H -D LOCALEDIR="/usr/share/locale" -D INFODIR="/usr/share/info" -D INFODIR2="/usr/share/info" -I . -I /usr/src/gnu/usr.bin/texinfo/info -I .. -I . -I /usr/src/gnu/usr.bin/texinfo/lib -I ../intl -I .. -I /usr/src/gnu/usr.bin/texinfo/info -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/gnu/usr.bin/texinfo/obj/info -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/gnu/usr.bin/texinfo/info/display.c
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | #include "info.h" |
23 | #include "display.h" |
24 | |
25 | extern int info_any_buffered_input_p (void); |
26 | |
27 | static void free_display (DISPLAY_LINE **display); |
28 | static DISPLAY_LINE **make_display (int width, int height); |
29 | |
30 | void handle_tag (char *tag); |
31 | void handle_tag_start (char *tag); |
32 | void handle_tag_end (char *tag); |
33 | |
34 | |
35 | |
36 | DISPLAY_LINE **the_display = (DISPLAY_LINE **)NULL; |
37 | |
38 | |
39 | int display_inhibited = 0; |
40 | |
41 | |
42 | void |
43 | display_initialize_display (int width, int height) |
44 | { |
45 | free_display (the_display); |
46 | the_display = make_display (width, height); |
47 | display_clear_display (the_display); |
48 | } |
49 | |
50 | |
51 | void |
52 | display_clear_display (DISPLAY_LINE **display) |
53 | { |
54 | register int i; |
55 | |
56 | for (i = 0; display[i]; i++) |
57 | { |
58 | display[i]->text[0] = '\0'; |
59 | display[i]->textlen = 0; |
60 | display[i]->inverse = 0; |
61 | } |
62 | } |
63 | |
64 | |
65 | int display_was_interrupted_p = 0; |
66 | |
67 | |
68 | |
69 | void |
70 | display_update_display (WINDOW *window) |
71 | { |
72 | register WINDOW *win; |
73 | |
74 | display_was_interrupted_p = 0; |
75 | |
76 | |
77 | for (win = window; win; win = win->next) |
78 | { |
79 | |
80 | if (((win->flags & W_WindowVisible) == 0) || |
81 | ((win->flags & W_UpdateWindow) == 0) || |
82 | (win->height == 0)) |
83 | continue; |
84 | |
85 | display_update_one_window (win); |
86 | if (display_was_interrupted_p) |
87 | break; |
88 | } |
89 | |
90 | |
91 | display_update_one_window (the_echo_area); |
92 | } |
93 | |
94 | void |
95 | handle_tag_start (char *tag) |
96 | { |
97 | |
98 | return; |
99 | } |
100 | |
101 | void |
102 | handle_tag_end (char *tag) |
103 | { |
104 | |
105 | return; |
106 | } |
107 | |
108 | void |
109 | handle_tag (char *tag) |
110 | { |
111 | if (tag[0] == '/') |
112 | { |
113 | tag++; |
114 | handle_tag_end (tag); |
115 | } |
116 | else |
117 | handle_tag_start (tag); |
118 | } |
119 | |
120 | |
121 | |
122 | void |
123 | display_update_one_window (WINDOW *win) |
124 | { |
125 | register char *nodetext; |
126 | register char *last_node_char; |
127 | register int i; |
128 | char *printed_line; |
129 | int pl_index = 0; |
130 | int line_index = 0; |
131 | int pl_ignore = 0; |
132 | int allocated_win_width; |
133 | DISPLAY_LINE **display = the_display; |
134 | |
135 | |
136 | if (display_inhibited) |
| 1 | Assuming 'display_inhibited' is 0 | |
|
| |
137 | display_was_interrupted_p = 1; |
138 | |
139 | |
140 | if (!win->height || display_inhibited) |
| 3 | | Assuming field 'height' is not equal to 0 | |
|
| |
141 | return; |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | if ((win->first_row < 0) || (win->first_row > the_screen->height)) |
| 5 | | Assuming field 'first_row' is >= 0 | |
|
| 6 | | Assuming field 'first_row' is <= field 'height' | |
|
| |
148 | return; |
149 | |
150 | |
151 | |
152 | |
153 | allocated_win_width = win->width + 1; |
154 | printed_line = (char *)xmalloc (allocated_win_width); |
155 | |
156 | if (!win->node || !win->line_starts) |
| 8 | | Assuming field 'node' is non-null | |
|
| 9 | | Assuming field 'line_starts' is non-null | |
|
| |
157 | goto done_with_node_display; |
158 | |
159 | nodetext = win->line_starts[win->pagetop]; |
160 | last_node_char = win->node->contents + win->node->nodelen; |
161 | |
162 | for (; nodetext < last_node_char; nodetext++) |
| 11 | | Loop condition is true. Entering loop body | |
|
163 | { |
164 | char *rep = NULL, *rep_carried_over, rep_temp[2]; |
165 | int replen; |
166 | |
167 | if (isprint (*nodetext)) |
| |
168 | { |
169 | rep_temp[0] = *nodetext; |
170 | replen = 1; |
171 | rep_temp[1] = '\0'; |
172 | rep = rep_temp; |
173 | } |
174 | else |
175 | { |
176 | if (*nodetext == '\r' || *nodetext == '\n') |
177 | { |
178 | replen = win->width - pl_index + pl_ignore; |
179 | } |
180 | else if (*nodetext == '\0' |
181 | && (nodetext + 2) < last_node_char |
182 | && *(nodetext + 1) == '\b' |
183 | && *(nodetext + 2) == '[') |
184 | { |
185 | |
186 | |
187 | int element_len = 0; |
188 | char *element; |
189 | |
190 | |
191 | nodetext += 3; |
192 | |
193 | while (!(*nodetext == '\0' |
194 | && *(nodetext + 1) == '\b' |
195 | && *(nodetext + 2) == ']')) |
196 | { |
197 | nodetext++; |
198 | element_len++; |
199 | } |
200 | |
201 | element = (char *) malloc (element_len + 1); |
202 | strncpy (element, nodetext - element_len, element_len); |
203 | |
204 | |
205 | nodetext += 2; |
206 | pl_ignore += element_len + 5; |
207 | |
208 | element[element_len] = '\0'; |
209 | |
210 | handle_tag (element); |
211 | |
212 | |
213 | free (element); |
214 | |
215 | continue; |
216 | } |
217 | else |
218 | { |
219 | rep = printed_representation (*nodetext, pl_index); |
220 | replen = strlen (rep); |
221 | } |
222 | } |
223 | |
224 | |
225 | if (raw_escapes_p |
| 13 | | Assuming 'raw_escapes_p' is 0 | |
|
226 | && *nodetext == '\033' |
227 | && nodetext[1] == '[' |
228 | && isdigit (nodetext[2])) |
229 | { |
230 | if (nodetext[3] == 'm') |
231 | pl_ignore += 4; |
232 | else if (isdigit (nodetext[3]) && nodetext[4] == 'm') |
233 | pl_ignore += 5; |
234 | } |
235 | while (pl_index + 2 >= allocated_win_width - 1) |
| 14 | | Assuming the condition is true | |
|
| 15 | | Loop condition is true. Entering loop body | |
|
| 16 | | Assuming the condition is false | |
|
| 17 | | Loop condition is false. Execution continues on line 243 | |
|
236 | { |
237 | allocated_win_width *= 2; |
238 | printed_line = (char *)xrealloc (printed_line, allocated_win_width); |
239 | } |
240 | |
241 | |
242 | |
243 | if (replen + pl_index < win->width + pl_ignore) |
| 18 | | Assuming the condition is false | |
|
| |
244 | { |
245 | |
246 | if (replen == 1) |
247 | { |
248 | printed_line[pl_index++] = *rep; |
249 | } |
250 | else |
251 | { |
252 | for (i = 0; i < replen; i++) |
253 | printed_line[pl_index++] = rep[i]; |
254 | } |
255 | } |
256 | else |
257 | { |
258 | DISPLAY_LINE *entry; |
259 | |
260 | |
261 | |
262 | |
263 | if (*nodetext == '\n' || *nodetext == '\r' || *nodetext == '\t') |
| |
264 | { |
265 | printed_line[pl_index] = '\0'; |
266 | rep_carried_over = (char *)NULL; |
267 | } |
268 | else |
269 | { |
270 | |
271 | |
272 | |
273 | |
274 | for (i = 0; pl_index < (win->width + pl_ignore - 1);) |
| 21 | | Assuming the condition is true | |
|
| 22 | | Loop condition is true. Entering loop body | |
|
| 23 | | Loop condition is true. Entering loop body | |
|
| 24 | | Loop condition is true. Entering loop body | |
|
275 | printed_line[pl_index++] = rep[i++]; |
| 25 | | Assigned value is garbage or undefined |
|
276 | |
277 | rep_carried_over = rep + i; |
278 | |
279 | |
280 | |
281 | |
282 | if (1 + line_index + win->first_row < the_screen->height) |
283 | { |
284 | if (win->flags & W_NoWrap) |
285 | printed_line[pl_index++] = '$'; |
286 | else |
287 | printed_line[pl_index++] = '\\'; |
288 | } |
289 | printed_line[pl_index] = '\0'; |
290 | } |
291 | |
292 | |
293 | |
294 | |
295 | entry = display[line_index + win->first_row]; |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | if ((entry && entry->inverse) |
302 | |
303 | || (raw_escapes_p && strchr (entry->text, '\033') != 0)) |
304 | { |
305 | terminal_goto_xy (0, line_index + win->first_row); |
306 | terminal_clear_to_eol (); |
307 | entry->inverse = 0; |
308 | entry->text[0] = '\0'; |
309 | entry->textlen = 0; |
310 | } |
311 | |
312 | |
313 | for (i = 0; i < pl_index; i++) |
314 | if (printed_line[i] != entry->text[i]) |
315 | break; |
316 | |
317 | |
318 | |
319 | if ((i != pl_index) || (pl_index != entry->textlen)) |
320 | { |
321 | |
322 | terminal_goto_xy (i, line_index + win->first_row); |
323 | |
324 | |
325 | if (i != pl_index) |
326 | terminal_put_text (printed_line + i); |
327 | |
328 | |
329 | |
330 | |
331 | if ((pl_index < win->width + pl_ignore |
332 | && pl_index < entry->textlen) |
333 | || (entry->inverse)) |
334 | terminal_clear_to_eol (); |
335 | |
336 | fflush (stdout); |
337 | |
338 | |
339 | if (strlen (printed_line) > (unsigned int) screenwidth) |
340 | |
341 | |
342 | |
343 | |
344 | |
345 | entry->text = xrealloc (entry->text, strlen (printed_line)+1); |
346 | strcpy (entry->text + i, printed_line + i); |
347 | entry->textlen = pl_index; |
348 | |
349 | |
350 | |
351 | entry->inverse = 0; |
352 | } |
353 | |
354 | |
355 | |
356 | if (++line_index == win->height) |
357 | break; |
358 | |
359 | |
360 | |
361 | |
362 | if (info_any_buffered_input_p ()) |
363 | { |
364 | free (printed_line); |
365 | display_was_interrupted_p = 1; |
366 | return; |
367 | } |
368 | |
369 | |
370 | pl_index = 0; |
371 | pl_ignore = 0; |
372 | |
373 | |
374 | |
375 | if (rep_carried_over) |
376 | for (; rep[pl_index]; pl_index++) |
377 | printed_line[pl_index] = rep[pl_index]; |
378 | |
379 | |
380 | |
381 | if (pl_index && (win->flags & W_NoWrap)) |
382 | { |
383 | char *begin; |
384 | |
385 | pl_index = 0; |
386 | printed_line[0] = '\0'; |
387 | |
388 | begin = nodetext; |
389 | |
390 | while ((nodetext < last_node_char) && (*nodetext != '\n')) |
391 | nodetext++; |
392 | } |
393 | } |
394 | } |
395 | |
396 | done_with_node_display: |
397 | |
398 | |
399 | |
400 | for (; line_index < win->height; line_index++) |
401 | { |
402 | DISPLAY_LINE *entry = display[line_index + win->first_row]; |
403 | |
404 | |
405 | if (entry && entry->textlen) |
406 | { |
407 | entry->textlen = 0; |
408 | entry->text[0] = '\0'; |
409 | |
410 | terminal_goto_xy (0, line_index + win->first_row); |
411 | terminal_clear_to_eol (); |
412 | } |
413 | } |
414 | |
415 | |
416 | |
417 | |
418 | if ((win->flags & W_InhibitMode) == 0) |
419 | { |
420 | window_make_modeline (win); |
421 | line_index = win->first_row + win->height; |
422 | |
423 | |
424 | |
425 | if ((!display[line_index]->inverse) || |
426 | (strcmp (display[line_index]->text, win->modeline) != 0)) |
427 | { |
428 | terminal_goto_xy (0, line_index); |
429 | terminal_begin_inverse (); |
430 | terminal_put_text (win->modeline); |
431 | terminal_end_inverse (); |
432 | strcpy (display[line_index]->text, win->modeline); |
433 | display[line_index]->inverse = 1; |
434 | display[line_index]->textlen = strlen (win->modeline); |
435 | fflush (stdout); |
436 | } |
437 | } |
438 | |
439 | |
440 | win->flags &= ~W_UpdateWindow; |
441 | free (printed_line); |
442 | fflush (stdout); |
443 | } |
444 | |
445 | |
446 | |
447 | |
448 | |
449 | |
450 | void |
451 | display_scroll_display (int start, int end, int amount) |
452 | { |
453 | register int i, last; |
454 | DISPLAY_LINE *temp; |
455 | |
456 | |
457 | if (!terminal_can_scroll) |
458 | return; |
459 | |
460 | |
461 | |
462 | if (!the_display[0]) |
463 | return; |
464 | |
465 | |
466 | if (info_any_buffered_input_p ()) |
467 | return; |
468 | |
469 | |
470 | terminal_scroll_terminal (start, end, amount); |
471 | |
472 | |
473 | if (amount > 0) |
474 | { |
475 | last = end + amount; |
476 | |
477 | |
478 | for (i = 0; i < (end - start); i++) |
479 | { |
480 | temp = the_display[last - i]; |
481 | the_display[last - i] = the_display[end - i]; |
482 | the_display[end - i] = temp; |
483 | } |
484 | |
485 | |
486 | |
487 | for (i = start; i != (start + amount); i++) |
488 | { |
489 | the_display[i]->text[0] = '\0'; |
490 | the_display[i]->textlen = 0; |
491 | the_display[i]->inverse = 0; |
492 | } |
493 | } |
494 | |
495 | if (amount < 0) |
496 | { |
497 | last = start + amount; |
498 | for (i = 0; i < (end - start); i++) |
499 | { |
500 | temp = the_display[last + i]; |
501 | the_display[last + i] = the_display[start + i]; |
502 | the_display[start + i] = temp; |
503 | } |
504 | |
505 | |
506 | |
507 | for (i = end + amount; i != end; i++) |
508 | { |
509 | the_display[i]->text[0] = '\0'; |
510 | the_display[i]->textlen = 0; |
511 | the_display[i]->inverse = 0; |
512 | } |
513 | } |
514 | } |
515 | |
516 | |
517 | |
518 | |
519 | |
520 | void |
521 | display_scroll_line_starts (WINDOW *window, int old_pagetop, |
522 | char **old_starts, int old_count) |
523 | { |
524 | register int i, old, new; |
525 | int last_new, last_old; |
526 | int old_first, new_first; |
527 | int unchanged_at_top = 0; |
528 | int already_scrolled = 0; |
529 | |
530 | |
531 | old_first = old_pagetop; |
532 | new_first = window->pagetop; |
533 | |
534 | |
535 | last_new = window->pagetop + (window->height - 1); |
536 | if (last_new > window->line_count) |
537 | last_new = window->line_count - 1; |
538 | |
539 | |
540 | last_old = old_pagetop + (window->height - 1); |
541 | if (last_old > old_count) |
542 | last_old = old_count - 1; |
543 | |
544 | for (old = old_first, new = new_first; |
545 | old < last_old && new < last_new; |
546 | old++, new++) |
547 | if (old_starts[old] != window->line_starts[new]) |
548 | break; |
549 | else |
550 | unchanged_at_top++; |
551 | |
552 | |
553 | for (old = old_first + unchanged_at_top; old < last_old; old++) |
554 | { |
555 | for (new = new_first; new < last_new; new++) |
556 | if (old_starts[old] == window->line_starts[new]) |
557 | { |
558 | |
559 | for (i = 0; (old + i) < last_old; i++) |
560 | if (old_starts[old + i] != window->line_starts[new + i]) |
561 | break; |
562 | |
563 | |
564 | { |
565 | int start, end, amount; |
566 | |
567 | start = (window->first_row |
568 | + ((old + already_scrolled) - old_pagetop)); |
569 | amount = new - (old + already_scrolled); |
570 | end = window->first_row + window->height; |
571 | |
572 | |
573 | |
574 | |
575 | if (amount > 0) |
576 | end -= amount; |
577 | |
578 | if ((end - start) > 0) |
579 | { |
580 | display_scroll_display (start, end, amount); |
581 | |
582 | |
583 | |
584 | old += i; |
585 | already_scrolled += amount; |
586 | } |
587 | } |
588 | } |
589 | } |
590 | } |
591 | |
592 | |
593 | void |
594 | display_cursor_at_point (WINDOW *window) |
595 | { |
596 | int vpos, hpos; |
597 | |
598 | vpos = window_line_of_point (window) - window->pagetop + window->first_row; |
599 | hpos = window_get_cursor_column (window); |
600 | terminal_goto_xy (hpos, vpos); |
601 | fflush (stdout); |
602 | } |
603 |
|
604 | |
605 | |
606 | |
607 | |
608 | |
609 | |
610 | |
611 | static DISPLAY_LINE ** |
612 | make_display (int width, int height) |
613 | { |
614 | register int i; |
615 | DISPLAY_LINE **display; |
616 | |
617 | display = (DISPLAY_LINE **)xmalloc ((1 + height) * sizeof (DISPLAY_LINE *)); |
618 | |
619 | for (i = 0; i < height; i++) |
620 | { |
621 | display[i] = (DISPLAY_LINE *)xmalloc (sizeof (DISPLAY_LINE)); |
622 | display[i]->text = (char *)xmalloc (1 + width); |
623 | display[i]->textlen = 0; |
624 | display[i]->inverse = 0; |
625 | } |
626 | display[i] = (DISPLAY_LINE *)NULL; |
627 | return (display); |
628 | } |
629 | |
630 | |
631 | static void |
632 | free_display (DISPLAY_LINE **display) |
633 | { |
634 | register int i; |
635 | register DISPLAY_LINE *display_line; |
636 | |
637 | if (!display) |
638 | return; |
639 | |
640 | for (i = 0; (display_line = display[i]); i++) |
641 | { |
642 | free (display_line->text); |
643 | free (display_line); |
644 | } |
645 | free (display); |
646 | } |