Bug Summary

File:src/lib/libcurses/widechar/lib_get_wch.c
Warning:line 126, column 13
Assigned value is garbage or undefined

Annotated Source Code

Press '?' to see keyboard shortcuts

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 -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/lib/libcurses/obj -resource-dir /usr/local/lib/clang/13.0.0 -I . -I /usr/src/lib/libcurses -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/* $OpenBSD: lib_get_wch.c,v 1.1 2010/09/06 17:26:17 nicm Exp $ */
2
3/****************************************************************************
4 * Copyright (c) 2002-2007,2008 Free Software Foundation, Inc. *
5 * *
6 * Permission is hereby granted, free of charge, to any person obtaining a *
7 * copy of this software and associated documentation files (the *
8 * "Software"), to deal in the Software without restriction, including *
9 * without limitation the rights to use, copy, modify, merge, publish, *
10 * distribute, distribute with modifications, sublicense, and/or sell *
11 * copies of the Software, and to permit persons to whom the Software is *
12 * furnished to do so, subject to the following conditions: *
13 * *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
16 * *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * *
25 * Except as contained in this notice, the name(s) of the above copyright *
26 * holders shall not be used in advertising or otherwise to promote the *
27 * sale, use or other dealings in this Software without prior written *
28 * authorization. *
29 ****************************************************************************/
30
31/****************************************************************************
32 * Author: Thomas E. Dickey 2002-on *
33 ****************************************************************************/
34
35/*
36** lib_get_wch.c
37**
38** The routine get_wch().
39**
40*/
41
42#include <curses.priv.h>
43#include <ctype.h>
44
45MODULE_ID("$Id: lib_get_wch.c,v 1.1 2010/09/06 17:26:17 nicm Exp $")
46
47#if HAVE_MBTOWC1 && HAVE_MBLEN1
48#define reset_mbytes(state)mblen(((void*)0), 0), mbtowc(((void*)0), ((void*)0), 0) mblen(NULL((void*)0), 0), mbtowc(NULL((void*)0), NULL((void*)0), 0)
49#define count_mbytes(buffer,length,state)mblen(buffer,length) mblen(buffer,length)
50#define check_mbytes(wch,buffer,length,state)(int) mbtowc(&wch, buffer, length) \
51 (int) mbtowc(&wch, buffer, length)
52#define state_unused
53#elif HAVE_MBRTOWC1 && HAVE_MBRLEN1
54#define reset_mbytes(state)mblen(((void*)0), 0), mbtowc(((void*)0), ((void*)0), 0) init_mb(state)memset(&state, 0, sizeof(state))
55#define count_mbytes(buffer,length,state)mblen(buffer,length) mbrlen(buffer,length,&state)
56#define check_mbytes(wch,buffer,length,state)(int) mbtowc(&wch, buffer, length) \
57 (int) mbrtowc(&wch, buffer, length, &state)
58#else
59make an error
60#endif
61
62NCURSES_EXPORT(int)int
63wget_wch(WINDOW *win, wint_t *result)
64{
65 SCREEN *sp;
66 int code;
67 char buffer[(MB_LEN_MAX4 * 9) + 1]; /* allow some redundant shifts */
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 * We can get a stream of single-byte characters and KEY_xxx codes from
80 * _nc_wgetch(), while we want to return a wide character or KEY_xxx code.
81 */
82 _nc_lock_global(curses);
83 sp = _nc_screen_of(win);
84 if (sp != 0) {
2
Assuming 'sp' is equal to null
3
Taking false branch
85 for (;;) {
86 T(("reading %d of %d", (int) count + 1, (int) sizeof(buffer)));
87 code = _nc_wgetch(win, &value, TRUE1 EVENTLIST_2nd((_nc_eventlist
88 *) 0));
89 if (code == ERR(-1)) {
90 break;
91 } else if (code == KEY_CODE_YES0400) {
92 /*
93 * If we were processing an incomplete multibyte character,
94 * return an error since we have a KEY_xxx code which
95 * interrupts it. For some cases, we could improve this by
96 * writing a new version of lib_getch.c(!), but it is not clear
97 * whether the improvement would be worth the effort.
98 */
99 if (count != 0) {
100 _nc_ungetch(sp, (int) value);
101 code = ERR(-1);
102 }
103 break;
104 } else if (count + 1 >= sizeof(buffer)) {
105 _nc_ungetch(sp, (int) value);
106 code = ERR(-1);
107 break;
108 } else {
109 buffer[count++] = (char) UChar(value)((unsigned char)(value));
110 reset_mbytes(state)mblen(((void*)0), 0), mbtowc(((void*)0), ((void*)0), 0);
111 status = count_mbytes(buffer, count, state)mblen(buffer,count);
112 if (status >= 0) {
113 reset_mbytes(state)mblen(((void*)0), 0), mbtowc(((void*)0), ((void*)0), 0);
114 if (check_mbytes(wch, buffer, count, state)(int) mbtowc(&wch, buffer, count) != status) {
115 code = ERR(-1); /* the two calls should match */
116 _nc_ungetch(sp, (int) value);
117 }
118 value = wch;
119 break;
120 }
121 }
122 }
123 } else {
124 code = ERR(-1);
125 }
126 *result = value;
4
Assigned value is garbage or undefined
127 _nc_unlock_global(curses);
128 T(("result %#lo", value));
129 returnCode(code)return code;
130}