Bug Summary

File:src/sbin/kbd/kbd_wscons.c
Warning:line 113, column 3
Value stored to 'found' is never read

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 kbd_wscons.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/sbin/kbd/obj -resource-dir /usr/local/lib/clang/13.0.0 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/sbin/kbd/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/sbin/kbd/kbd_wscons.c
1/* $OpenBSD: kbd_wscons.c,v 1.34 2020/01/22 06:24:07 tedu Exp $ */
2
3/*
4 * Copyright (c) 2001 Mats O Jansson. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/ioctl.h>
28#include <sys/time.h>
29#include <dev/wscons/wsconsio.h>
30#include <dev/wscons/wsksymdef.h>
31
32#include <err.h>
33#include <errno(*__errno()).h>
34#include <fcntl.h>
35#include <limits.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <unistd.h>
40
41#define NUM_KBD10 10
42
43char *kbtype_tab[] = {
44 "pc-xt/pc-at",
45 "usb",
46 "adb",
47 "lk201",
48 "sun",
49 "sun5",
50 "hil",
51 "gsc",
52 "sgi"
53};
54enum { SA_PCKBD,
55 SA_UKBD,
56 SA_AKBD,
57 SA_LKKBD,
58 SA_SUNKBD,
59 SA_SUN5KBD,
60 SA_HILKBD,
61 SA_GSCKBD,
62 SA_SGIKBD,
63
64 SA_MAX
65};
66
67struct nameint {
68 int value;
69 char *name;
70};
71
72struct nameint kbdenc_tab[] = {
73 KB_ENCTAB{ 0x0100, "user" }, { 0x0200, "us" }, { 0x0300, "de" }, { 0x0400
, "dk" }, { 0x0500, "it" }, { 0x0600, "fr" }, { 0x0700, "uk" }
, { 0x0800, "jp" }, { 0x0900, "sv" }, { 0x0a00, "no" }, { 0x0b00
, "es" }, { 0x0c00, "hu" }, { 0x0d00, "be" }, { 0x0e00, "ru" }
, { 0x1200, "ua" }, { 0x0f00, "sg" }, { 0x1000, "sf" }, { 0x1100
, "pt" }, { 0x1300, "lt" }, { 0x1400, "la" }, { 0x1500, "br" }
, { 0x1600, "nl" }, { 0x1700, "tr" }, { 0x1800, "pl" }, { 0x1900
, "si" }, { 0x1a00, "cf" }, { 0x1b00, "lv" }, { 0x1c00, "is" }
, { 0x1d00, "ee" }
74 ,
75 { 0, NULL((void *)0) }
76};
77
78struct nameint kbdvar_tab[] = {
79 KB_VARTAB{ 0x00000001, "nodead" }, { 0x00000002, "declk" }, { 0x00000004
, "lk401" }, { 0x00000008, "swapctrlcaps" }, { 0x00000010, "dvorak"
}, { 0x00000020, "metaesc" }, { 0x00000040, "iopener" }, { 0x00000080
, "noencoding" }, { 0x00010000, "apple" }, { 0x02000000, "colemak"
}
80 ,
81 { 0, NULL((void *)0) }
82};
83
84extern char *__progname;
85
86void kbd_show_enc(struct wskbd_encoding_data *encs, int idx);
87void kbd_get_encs(int fd, struct wskbd_encoding_data *encs);
88void kbd_list(void);
89void kbd_set(char *name, int verbose);
90
91void
92kbd_show_enc(struct wskbd_encoding_data *encs, int idx)
93{
94 int found;
95 kbd_t encoding, variant;
96 struct nameint *n;
97 int i;
98
99 printf("tables available for %s keyboard:\nencoding\n\n",
100 kbtype_tab[idx]);
101
102 for (i = 0; i < encs->nencodings; i++) {
103 found = 0;
104 encoding = encs->encodings[i];
105 for (n = &kbdenc_tab[0]; n->value; n++) {
106 if (n->value == KB_ENCODING(encoding)((encoding) & 0x0000ff00)) {
107 printf("%s", n->name);
108 found++;
109 }
110 }
111 if (found == 0)
112 printf("<encoding 0x%04x>", KB_ENCODING(encoding)((encoding) & 0x0000ff00));
113 found = 0;
Value stored to 'found' is never read
114 variant = KB_VARIANT(encoding)((encoding) & 0xffff00ff);
115 for (n = &kbdvar_tab[0]; n->value; n++) {
116 if ((n->value & KB_VARIANT(encoding)((encoding) & 0xffff00ff)) == n->value) {
117 printf(".%s", n->name);
118 variant &= ~n->value;
119 }
120 }
121 if (variant != 0)
122 printf(".<variant 0x%08x>", variant);
123 printf("\n");
124 }
125 printf("\n");
126}
127
128void
129kbd_get_encs(int fd, struct wskbd_encoding_data *encs)
130{
131 int nencodings = 64;
132
133 encs->nencodings = nencodings;
134 while (encs->nencodings == nencodings) {
135 encs->encodings = reallocarray(encs->encodings,
136 encs->nencodings, sizeof(kbd_t));
137 if (encs->encodings == NULL((void *)0))
138 err(1, NULL((void *)0));
139 if (ioctl(fd, WSKBDIO_GETENCODINGS(((unsigned long)0x80000000|(unsigned long)0x40000000) | ((sizeof
(struct wskbd_encoding_data) & 0x1fff) << 16) | (((
'W')) << 8) | ((21)))
, encs) == -1)
140 err(1, "WSKBDIO_GETENCODINGS");
141 if (encs->nencodings == nencodings) {
142 nencodings *= 2;
143 encs->nencodings = nencodings;
144 }
145 }
146}
147
148void
149kbd_list(void)
150{
151 int kbds[SA_MAX];
152 struct wskbd_encoding_data encs[SA_MAX];
153 int fd, i, kbtype, t;
154 char device[PATH_MAX1024];
155
156 memset(kbds, 0, sizeof(kbds));
157 memset(encs, 0, sizeof(encs));
158
159 /* Go through all keyboards. */
160 for (i = 0; i < NUM_KBD10; i++) {
161 (void) snprintf(device, sizeof device, "/dev/wskbd%d", i);
162 fd = open(device, O_WRONLY0x0001);
163 if (fd == -1)
164 fd = open(device, O_RDONLY0x0000);
165 if (fd >= 0) {
166 if (ioctl(fd, WSKBDIO_GTYPE((unsigned long)0x40000000 | ((sizeof(u_int) & 0x1fff) <<
16) | ((('W')) << 8) | ((0)))
, &kbtype) == -1)
167 err(1, "WSKBDIO_GTYPE");
168 switch (kbtype) {
169 case WSKBD_TYPE_PC_XT3:
170 case WSKBD_TYPE_PC_AT4:
171 t = SA_PCKBD;
172 break;
173 case WSKBD_TYPE_USB5:
174 t = SA_UKBD;
175 break;
176 case WSKBD_TYPE_ADB10:
177 t = SA_AKBD;
178 break;
179 case WSKBD_TYPE_LK2011:
180 case WSKBD_TYPE_LK4012:
181 t = SA_LKKBD;
182 break;
183 case WSKBD_TYPE_SUN11:
184 t = SA_SUNKBD;
185 break;
186 case WSKBD_TYPE_SUN512:
187 t = SA_SUN5KBD;
188 break;
189 case WSKBD_TYPE_HIL13:
190 t = SA_HILKBD;
191 break;
192 case WSKBD_TYPE_GSC14:
193 t = SA_GSCKBD;
194 break;
195 case WSKBD_TYPE_SGI20:
196 t = SA_SGIKBD;
197 break;
198 default:
199 t = SA_MAX;
200 break;
201 }
202
203 if (t != SA_MAX) {
204 kbds[t]++;
205 if (encs[t].encodings == NULL((void *)0))
206 kbd_get_encs(fd, &encs[t]);
207 }
208 close(fd);
209 }
210 }
211
212 for (i = 0; i < SA_MAX; i++)
213 if (kbds[i] != 0)
214 kbd_show_enc(&encs[i], i);
215
216 for (i = 0; i < SA_MAX; i++)
217 free(encs[i].encodings);
218}
219
220void
221kbd_set(char *name, int verbose)
222{
223 char buf[LINE_MAX2048], *c, *b, device[sizeof "/dev/wskbd00"];
224 int map = 0, v, i, fd;
225 struct nameint *n;
226
227 c = name;
228 b = buf;
229 while (*c != '.' && *c != '\0' && b < buf + sizeof(buf) - 1)
230 *b++ = *c++;
231 *b = '\0';
232 n = &kbdenc_tab[0];
233 while (n->value) {
234 if (strcmp(n->name, buf) == 0)
235 map = n->value;
236 n++;
237 }
238 if (map == 0)
239 errx(1, "unknown encoding %s", buf);
240 while (*c == '.') {
241 b = buf;
242 c++;
243 while (*c != '.' && *c != '\0' && b < buf + sizeof(buf) - 1)
244 *b++ = *c++;
245 *b = '\0';
246 v = 0;
247 for (n = &kbdvar_tab[0]; n->value; n++) {
248 if (strcmp(n->name, buf) == 0)
249 v = n->value;
250 }
251 if (v == 0)
252 errx(1, "unknown variant %s", buf);
253 map |= v;
254 }
255
256 /* Go through all keyboards. */
257 v = 0;
258 for (i = 0; i < NUM_KBD10; i++) {
259 (void) snprintf(device, sizeof device, "/dev/wskbd%d", i);
260 fd = open(device, O_WRONLY0x0001);
261 if (fd == -1)
262 fd = open(device, O_RDONLY0x0000);
263 if (fd >= 0) {
264 if (ioctl(fd, WSKBDIO_SETENCODING((unsigned long)0x80000000 | ((sizeof(kbd_t) & 0x1fff) <<
16) | ((('W')) << 8) | ((16)))
, &map) == -1) {
265 if (errno(*__errno()) == EINVAL22) {
266 fprintf(stderr(&__sF[2]),
267 "%s: unsupported encoding %s on %s\n",
268 __progname, name, device);
269 } else
270 err(1, "WSKBDIO_SETENCODING: %s", device);
271 v--;
272 }
273 v++;
274 close(fd);
275 }
276 }
277
278 if (verbose && v > 0)
279 fprintf(stderr(&__sF[2]), "kbd: keyboard mapping set to %s\n", name);
280}