Bug Summary

File:_build/../src/mev.c
Warning:line 383, column 3
Value stored to 'stop' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name mev.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 2 -pic-is-pie -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/_build -resource-dir /usr/lib/llvm-16/lib/clang/16 -I src/mev.p -I src -I ../src -I . -I .. -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-address-of-packed-member -Wno-missing-field-initializers -Wno-packed -Wno-switch-enum -Wno-unused-parameter -Wwrite-strings -std=gnu11 -fconst-strings -fdebug-compilation-dir=/rootdir/_build -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-08-05-222352-10670-1 -x c ../src/mev.c
1/*
2 * Copyright (C) 2003 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <config.h>
20#include <sys/types.h>
21#ifdef HAVE_SYS_TERMIOS_H
22#include <sys/termios.h>
23#endif
24#include <sys/time.h>
25#include <stdio.h>
26#include <fcntl.h>
27#include <signal.h>
28#include <string.h>
29#ifdef HAVE_TERMIOS_H
30#include <termios.h>
31#endif
32#include <unistd.h>
33#include <glib.h>
34#include "caps.hh"
35
36#ifdef HAVE_SYS_SELECT_H
37#include <sys/select.h>
38#endif
39
40enum {
41 tracking_x10 = 9,
42 tracking_mouse = 1000,
43 tracking_hilite = 1001,
44 tracking_cell_motion = 1002,
45 tracking_all_motion = 1003,
46 tracking_focus = 1004,
47 tracking_xterm_ext = 1006,
48};
49
50static int tracking_mode = 0;
51static gboolean tracking_focus_mode = FALSE(0);
52
53static void
54decset(int mode, gboolean value)
55{
56 fprintf(stdoutstdout, _BTE_CAP_CSI"\033" "[" "?%d%c", mode, value ? 'h' : 'l');
57}
58
59static void
60reset_mouse_tracking_mode(void)
61{
62 decset(tracking_x10, FALSE(0));
63 decset(tracking_mouse, FALSE(0));
64 decset(tracking_hilite, FALSE(0));
65 decset(tracking_cell_motion, FALSE(0));
66 decset(tracking_all_motion, FALSE(0));
67 decset(tracking_xterm_ext, FALSE(0));
68 fflush(stdoutstdout);
69}
70
71static void
72reset(void)
73{
74 reset_mouse_tracking_mode();
75 decset(tracking_focus, FALSE(0));
76 fflush(stdoutstdout);
77}
78
79static void
80clear(void)
81{
82 fprintf(stdoutstdout, "%s",
83 _BTE_CAP_ESC"\033" "7"
84 _BTE_CAP_CSI"\033" "[" "11;1H"
85 _BTE_CAP_CSI"\033" "[" "1J"
86 _BTE_CAP_CSI"\033" "[" "2K"
87 _BTE_CAP_CSI"\033" "[" "1;1H");
88 reset_mouse_tracking_mode();
89 switch (tracking_mode) {
90 case tracking_x10:
91 fprintf(stdoutstdout, "X10 tracking enabled.\r\n");
92 decset(tracking_x10, TRUE(!(0)));
93 break;
94 case tracking_mouse:
95 fprintf(stdoutstdout, "Mouse tracking enabled.\r\n");
96 decset(tracking_mouse, TRUE(!(0)));
97 break;
98 case tracking_hilite:
99 fprintf(stdoutstdout, "Hilite tracking enabled.\r\n");
100 decset(tracking_hilite, TRUE(!(0)));
101 break;
102 case tracking_cell_motion:
103 fprintf(stdoutstdout, "Cell motion tracking enabled.\r\n");
104 decset(tracking_cell_motion, TRUE(!(0)));
105 break;
106 case tracking_all_motion:
107 fprintf(stdoutstdout, "All motion tracking enabled.\r\n");
108 decset(tracking_all_motion, TRUE(!(0)));
109 break;
110 case tracking_xterm_ext:
111 fprintf(stdoutstdout, "Xterm 1006 mouse tracking extension enabled.\r\n");
112 decset(tracking_xterm_ext, TRUE(!(0)));
113 break;
114 default:
115 fprintf(stdoutstdout, "Tracking disabled.\r\n");
116 break;
117 }
118 fprintf(stdoutstdout, "Tracking focus %s.\r\n", tracking_focus_mode ? "enabled":"disabled");
119 fprintf(stdoutstdout, "A - X10.\r\n");
120 fprintf(stdoutstdout, "B - Mouse tracking.\r\n");
121 fprintf(stdoutstdout, "C - Hilite tracking [FIXME: NOT IMPLEMENTED].\r\n");
122 fprintf(stdoutstdout, "D - Cell motion tracking.\r\n");
123 fprintf(stdoutstdout, "E - All motion tracking.\r\n");
124 fprintf(stdoutstdout, "F - Xterm 1006 extension.\r\n");
125 fprintf(stdoutstdout, "I - Focus tracking.\r\n");
126 fprintf(stdoutstdout, "Q - Quit.\r\n");
127 fprintf(stdoutstdout, "%s", _BTE_CAP_ESC"\033" "8");
128 fflush(stdoutstdout);
129}
130
131static gsize
132parse_legacy_mouse_mode(const guint8 *data,
133 gsize len)
134{
135 int button = 0;
136 const char *shift = "", *control = "", *alt = "";
137 gboolean motion = FALSE(0);
138 int x, y;
139 guint8 b;
140
141 if (len < 6)
142 return 0;
143
144 b = data[3] - 32;
145 switch (b & 3) {
146 case 0:
147 button = 1;
148 if (b & 64) {
149 button += 3;
150 }
151 break;
152 case 1:
153 button = 2;
154 if (b & 64) {
155 button += 3;
156 }
157 break;
158 case 2:
159 button = 3;
160 if (b & 64) {
161 button += 3;
162 }
163 break;
164 case 3:
165 button = 0;
166 break;
167 }
168 shift = b & 4 ?
169 "[shift]" :
170 "";
171 alt = b & 8 ?
172 "[alt]" :
173 "";
174 control = b & 16 ?
175 "[control]" :
176 "";
177 motion = (b & 32) != 0;
178 x = data[4] - 32;
179 y = data[5] - 32;
180 fprintf(stdoutstdout, "%d %s%s%s(%s%s%s) at %d,%d\r\n",
181 button,
182 motion ? "motion " : "",
183 (!motion && button) ? "press" : "",
184 (!motion && !button) ? "release" : "",
185 alt, control, shift,
186 x, y);
187
188 return 6;
189}
190
191static gsize
192parse_esc(guint8 *data,
193 gsize len)
194{
195 if (len < 3)
196 return 0;
197
198 if (!(data[0] == '\033' && data[1] == '[')) /* CSI ? */
199 return 0;
200
201 if (data[2] == 'M')
202 return parse_legacy_mouse_mode(data, len);
203
204 /* FIXME: add support for xterm extended mode (1006) */
205
206 if (data[2] == 'I' || data[2] == 'O') {
207 fprintf(stdoutstdout, "focus %s\r\n", data[2] == 'I' ? "in" : "out");
208 return 3;
209 }
210
211 return 0;
212}
213
214static gsize
215print_data(guint8 *data,
216 gsize len)
217{
218 static const char codes[][6] = {
219 "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
220 "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
221 "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
222 "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US",
223 "SPACE"
224 };
225 gsize i;
226
227 if (len == 0)
228 return 0;
229
230 for (i = 0; i < len; i++) {
231 guint8 c = (guint8)data[i];
232
233 if (c == '\033' /* ESC */) {
234 switch (data[++i]) {
235 case '_': fprintf(stdoutstdout, "APC "); break;
236 case '[': fprintf(stdoutstdout, "CSI "); break;
237 case 'P': fprintf(stdoutstdout, "DCS "); break;
238 case ']': fprintf(stdoutstdout, "OSC "); break;
239 case '^': fprintf(stdoutstdout, "PM "); break;
240 case '\\': fprintf(stdoutstdout, "ST "); break;
241 default: fprintf(stdoutstdout, "ESC "); i--; break;
242 }
243 }
244 else if (c <= 0x20)
245 fprintf(stdoutstdout, "%s ", codes[c]);
246 else if (c == 0x7f)
247 fprintf(stdoutstdout, "DEL ");
248 else if (c >= 0x80)
249 fprintf(stdoutstdout, "\\%02x ", c);
250 else
251 fprintf(stdoutstdout, "%c ", c);
252 }
253
254 return len;
255}
256
257static gboolean
258parse(void)
259{
260 GByteArray *bytes;
261 guchar buffer[64];
262 gsize i, length;
263 gboolean ret = FALSE(0);
264
265 bytes = g_byte_array_new();
266 if ((length = read(STDIN_FILENO0, buffer, sizeof(buffer))) > 0) {
267 g_byte_array_append(bytes, buffer, length);
268 }
269
270 i = 0;
271 while (i < bytes->len) {
272 switch (bytes->data[i]) {
273 case 'A':
274 case 'a':
275 tracking_mode = (tracking_mode == tracking_x10) ?
276 0 : tracking_x10;
277 i++;
278 break;
279 case 'B':
280 case 'b':
281 tracking_mode = (tracking_mode == tracking_mouse) ?
282 0 : tracking_mouse;
283 i++;
284 break;
285 case 'C':
286 case 'c':
287 tracking_mode = (tracking_mode == tracking_hilite) ?
288 0 : tracking_hilite;
289 i++;
290 break;
291 case 'D':
292 case 'd':
293 tracking_mode = (tracking_mode == tracking_cell_motion) ?
294 0 : tracking_cell_motion;
295 i++;
296 break;
297 case 'E':
298 case 'e':
299 tracking_mode = (tracking_mode == tracking_all_motion) ?
300 0 : tracking_all_motion;
301 i++;
302 break;
303 case 'F':
304 case 'f':
305 tracking_mode = (tracking_mode == tracking_xterm_ext) ?
306 0 : tracking_xterm_ext;
307 i++;
308 break;
309 case 'I':
310 case 'i':
311 tracking_focus_mode = !tracking_focus_mode;
312 decset(tracking_focus, tracking_focus_mode);
313 i++;
314 break;
315 case 'Q':
316 case 'q':
317 ret = TRUE(!(0));
318 i++;
319 break;
320 case '\033': {
321 gsize consumed = parse_esc(&bytes->data[i], bytes->len - i);
322 if (consumed > 0) {
323 i += consumed;
324 break;
325 }
326 }
327 /* fallthrough */
328 default:
329 i += print_data(&bytes->data[i], bytes->len - i);
330 fprintf(stdoutstdout, "\r\n");
331 break;
332 }
333 }
334 fflush(stdoutstdout);
335 g_byte_array_free(bytes, TRUE(!(0)));
336
337 return ret;
338}
339
340static struct termios tcattr, original;
341
342G_GNUC_NORETURN__attribute__ ((__noreturn__))
343static void
344sigint_handler(int signum)
345{
346 if (tcsetattr(STDIN_FILENO0, TCSANOW0, &original) != 0) {
347 perror("tcsetattr");
348 }
349 reset();
350 _exit(1);
351}
352
353int
354main(int argc, char **argv)
355{
356 int flags;
357 gboolean stop;
358 fd_set in_fds;
359
360 if (tcgetattr(STDIN_FILENO0, &tcattr) != 0) {
361 perror("tcgetattr");
362 return 1;
363 }
364
365 original = tcattr;
366 signal(SIGINT2, sigint_handler);
367 cfmakeraw(&tcattr);
368 if (tcsetattr(STDIN_FILENO0, TCSANOW0, &tcattr) != 0) {
369 perror("tcsetattr");
370 return 1;
371 }
372
373 flags = fcntl(STDIN_FILENO0, F_GETFL3);
374 fcntl(STDIN_FILENO0, F_SETFL4, flags & ~(O_NONBLOCK04000));
375 fprintf(stdoutstdout, "%s",
376 _BTE_CAP_CSI"\033" "[" "12;1H"
377 _BTE_CAP_CSI"\033" "[" "2K"
378 _BTE_CAP_CSI"\033" "[" "2J");
379 do {
380 clear();
381 FD_ZERO(&in_fds)do { unsigned int __i; fd_set *__arr = (&in_fds); for (__i
= 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) (
(__arr)->fds_bits)[__i] = 0; } while (0)
;
382 FD_SET(STDIN_FILENO, &in_fds)((void) (((&in_fds)->fds_bits)[((0) / (8 * (int) sizeof
(__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int
) sizeof (__fd_mask)))))))
;
383 stop = TRUE(!(0));
Value stored to 'stop' is never read
384 switch (select(STDIN_FILENO0 + 1, &in_fds, NULL((void*)0), NULL((void*)0), NULL((void*)0))) {
385 case 1:
386 stop = parse();
387 break;
388 default:
389 stop = TRUE(!(0));
390 break;
391 }
392 } while (!stop);
393 reset();
394 fcntl(STDIN_FILENO0, F_SETFL4, flags);
395
396 if (tcsetattr(STDIN_FILENO0, TCSANOW0, &original) != 0) {
397 perror("tcsetattr");
398 return 1;
399 }
400
401 return 0;
402}