Bug Summary

File:frontends/monkey/dispatch.c
Warning:line 88, column 11
Although the value stored to 'r' is used in the enclosing expression, the value is never actually read from 'r'

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 dispatch.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 2 -pic-is-pie -mframe-pointer=none -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=/var/lib/jenkins/workspace/scan-build-netsurf -resource-dir /usr/lib/llvm-14/lib/clang/14.0.6 -I . -I include -I build/Linux-monkey -I frontends -I content/handlers -D WITH_JPEG -U WITH_PDF_EXPORT -D LIBICONV_PLUG -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -I /usr/include/x86_64-linux-gnu -D WITH_CURL -D WITH_OPENSSL -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D UTF8PROC_EXPORTS -D WITH_UTF8PROC -D WITH_WEBP -I /usr/include/libpng16 -D WITH_PNG -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include/ -D WITH_BMP -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D WITH_GIF -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D WITH_NSPSL -I /var/lib/jenkins/artifacts-x86_64-linux-gnu/include -D WITH_NSLOG -D NETSURF_UA_FORMAT_STRING="Mozilla/5.0 (%s) NetSurf/%d.%d" -D NETSURF_HOMEPAGE="about:welcome" -D NETSURF_LOG_LEVEL=VERBOSE -D NETSURF_BUILTIN_LOG_FILTER="(level:WARNING || cat:jserrors)" -D NETSURF_BUILTIN_VERBOSE_FILTER="(level:VERBOSE || cat:jserrors)" -D STMTEXPR=1 -D monkey -D nsmonkey -D MONKEY_RESPATH="/var/lib/jenkins/artifacts-x86_64-linux-gnu/share/netsurf/" -D _POSIX_C_SOURCE=200809L -D _XOPEN_SOURCE=700 -D _BSD_SOURCE -D _DEFAULT_SOURCE -D _NETBSD_SOURCE -D DUK_OPT_HAVE_CUSTOM_H -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wwrite-strings -Wno-unused-parameter -Wno-unused-but-set-variable -std=c99 -fconst-strings -fdebug-compilation-dir=/var/lib/jenkins/workspace/scan-build-netsurf -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-display-progress -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/lib/jenkins/workspace/scan-build-netsurf/clangScanBuildReports/2024-09-27-095240-3006188-1 -x c frontends/monkey/dispatch.c
1/*
2 * Copyright 2011 Daniel Silverstone <dsilvers@digital-scurf.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <limits.h>
20#include <stdio.h>
21#include <string.h>
22#include <stdlib.h>
23
24#include "utils/log.h"
25#include "utils/utils.h"
26#include "utils/ring.h"
27
28#include "monkey/dispatch.h"
29
30typedef struct cmdhandler {
31 struct cmdhandler *r_next, *r_prev;
32 char *cmd;
33 handle_command_fn fn;
34} monkey_cmdhandler_t;
35
36static monkey_cmdhandler_t *handler_ring = NULL((void*)0);
37
38nserror
39monkey_register_handler(const char *cmd, handle_command_fn fn)
40{
41 monkey_cmdhandler_t *ret = calloc(1, sizeof(*ret));
42 if (ret == NULL((void*)0)) {
43 NSLOG(netsurf, INFO, "Unable to allocate handler")do { if (NSLOG_LEVEL_INFO >= NSLOG_LEVEL_VERBOSE) { static
nslog_entry_context_t _nslog_ctx = { &__nslog_category_netsurf
, NSLOG_LEVEL_INFO, "frontends/monkey/dispatch.c", sizeof("frontends/monkey/dispatch.c"
) - 1, __PRETTY_FUNCTION__, sizeof(__PRETTY_FUNCTION__) - 1, 43
, }; nslog__log(&_nslog_ctx, "Unable to allocate handler"
); } } while(0)
;
44 return NSERROR_NOMEM;
45 }
46 ret->cmd = strdup(cmd);
47 ret->fn = fn;
48 RING_INSERT(handler_ring, ret)if (handler_ring) { ret->r_next = handler_ring; ret->r_prev
= handler_ring->r_prev; handler_ring->r_prev = ret; ret
->r_prev->r_next = ret; } else handler_ring = ret->r_prev
= ret->r_next = ret
;
49 return NSERROR_OK;
50}
51
52void
53monkey_free_handlers(void)
54{
55 while (handler_ring != NULL((void*)0)) {
56 monkey_cmdhandler_t *handler = handler_ring;
57 RING_REMOVE(handler_ring, handler)if (handler->r_next != handler ) { handler->r_next->
r_prev = handler->r_prev; handler->r_prev->r_next = handler
->r_next; if (handler_ring == handler) handler_ring = handler
->r_next; } else { handler_ring = 0; } handler->r_next =
handler->r_prev = 0
;
58 free(handler->cmd);
59 free(handler);
60 }
61}
62
63void
64monkey_process_command(void)
65{
66 char buffer[PATH_MAX4096];
67 int argc = 0;
68 char **argv = NULL((void*)0);
69 char *p, *r = NULL((void*)0);
70 handle_command_fn fn = NULL((void*)0);
71 char **nargv;
72
73 if (fgets(buffer, PATH_MAX4096, stdinstdin) == NULL((void*)0)) {
74 /* end of input or read error so issue QUIT */
75 sprintf(buffer, "QUIT\n");
76 }
77
78 /* remove newline */
79 buffer[strlen(buffer) - 1] = '\0';
80
81 argv = malloc(sizeof *argv);
82 if (argv == NULL((void*)0)) {
83 return;
84 }
85 argc = 1;
86 *argv = buffer;
87
88 for (p = r = buffer; *p != '\0'; p++) {
Although the value stored to 'r' is used in the enclosing expression, the value is never actually read from 'r'
89 if (*p == ' ') {
90 nargv = realloc(argv, sizeof(*argv) * (argc + 1));
91 if (nargv == NULL((void*)0)) {
92 /* reallocation of argument vector failed, try using what is
93 * already processed.
94 */
95 break;
96 } else {
97 argv = nargv;
98 }
99 argv[argc++] = r = p + 1;
100 *p = '\0';
101 }
102 }
103
104 RING_ITERATE_START(monkey_cmdhandler_t, handler_ring, handler)if (handler_ring != ((void*)0)) { monkey_cmdhandler_t *handler
= handler_ring; do { do {
{
105 if (strcmp(argv[0], handler->cmd) == 0) {
106 fn = handler->fn;
107 RING_ITERATE_STOP(handler_ring, handler)goto iteration_end_ring_handler;
108 }
109 } RING_ITERATE_END(handler_ring, handler)} while (0); handler = handler->r_next; } while (handler !=
handler_ring); } iteration_end_ring_handler:
;
110
111 if (fn != NULL((void*)0)) {
112 fn(argc, argv);
113 }
114
115 free(argv);
116}