clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name lib_get_wch.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/libcurses/obj -resource-dir /usr/local/lib/clang/13.0.0 -I . -I /usr/src/lib/libcurses -D PIC -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libcurses/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/libcurses/widechar/lib_get_wch.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 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | #include <curses.priv.h> |
| 43 | #include <ctype.h> |
| 44 | |
| 45 | MODULE_ID("$Id: lib_get_wch.c,v 1.1 2010/09/06 17:26:17 nicm Exp $") |
| 46 | |
| 47 | #if HAVE_MBTOWC && HAVE_MBLEN |
| 48 | #define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0) |
| 49 | #define count_mbytes(buffer,length,state) mblen(buffer,length) |
| 50 | #define check_mbytes(wch,buffer,length,state) \ |
| 51 | (int) mbtowc(&wch, buffer, length) |
| 52 | #define state_unused |
| 53 | #elif HAVE_MBRTOWC && HAVE_MBRLEN |
| 54 | #define reset_mbytes(state) init_mb(state) |
| 55 | #define count_mbytes(buffer,length,state) mbrlen(buffer,length,&state) |
| 56 | #define check_mbytes(wch,buffer,length,state) \ |
| 57 | (int) mbrtowc(&wch, buffer, length, &state) |
| 58 | #else |
| 59 | make an error |
| 60 | #endif |
| 61 | |
| 62 | NCURSES_EXPORT(int) |
| 63 | wget_wch(WINDOW *win, wint_t *result) |
| 64 | { |
| 65 | SCREEN *sp; |
| 66 | int code; |
| 67 | char buffer[(MB_LEN_MAX * 9) + 1]; |
| 68 | int status; |
| 69 | size_t count = 0; |
| 70 | unsigned long value; |
| 1 | 'value' declared without an initial value | |
|
| 71 | wchar_t wch; |
| 72 | #ifndef state_unused |
| 73 | mbstate_t state; |
| 74 | #endif |
| 75 | |
| 76 | T((T_CALLED("wget_wch(%p)"), win)); |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | _nc_lock_global(curses); |
| 83 | sp = _nc_screen_of(win); |
| 84 | if (sp != 0) { |
| 2 | | Assuming 'sp' is equal to null | |
|
| |
| 85 | for (;;) { |
| 86 | T(("reading %d of %d", (int) count + 1, (int) sizeof(buffer))); |
| 87 | code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist |
| 88 | *) 0)); |
| 89 | if (code == ERR) { |
| 90 | break; |
| 91 | } else if (code == KEY_CODE_YES) { |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | if (count != 0) { |
| 100 | _nc_ungetch(sp, (int) value); |
| 101 | code = ERR; |
| 102 | } |
| 103 | break; |
| 104 | } else if (count + 1 >= sizeof(buffer)) { |
| 105 | _nc_ungetch(sp, (int) value); |
| 106 | code = ERR; |
| 107 | break; |
| 108 | } else { |
| 109 | buffer[count++] = (char) UChar(value); |
| 110 | reset_mbytes(state); |
| 111 | status = count_mbytes(buffer, count, state); |
| 112 | if (status >= 0) { |
| 113 | reset_mbytes(state); |
| 114 | if (check_mbytes(wch, buffer, count, state) != status) { |
| 115 | code = ERR; |
| 116 | _nc_ungetch(sp, (int) value); |
| 117 | } |
| 118 | value = wch; |
| 119 | break; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } else { |
| 124 | code = ERR; |
| 125 | } |
| 126 | *result = value; |
| 4 | | Assigned value is garbage or undefined |
|
| 127 | _nc_unlock_global(curses); |
| 128 | T(("result %#lo", value)); |
| 129 | returnCode(code); |
| 130 | } |