Bug Summary

File:src/usr.sbin/nsd/obj/conftest.c
Warning:line 116, column 4
Value stored to 'number' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name conftest.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 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -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/usr.sbin/nsd/obj -resource-dir /usr/local/llvm16/lib/clang/16 -internal-isystem /usr/local/llvm16/lib/clang/16/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/nsd/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fcf-protection=branch -fno-jump-tables -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/scan/2024-01-11-140451-98009-1 -x c conftest.c
1/* confdefs.h */
2#define PACKAGE_NAME"NSD" "NSD"
3#define PACKAGE_TARNAME"nsd" "nsd"
4#define PACKAGE_VERSION"4.8.0" "4.8.0"
5#define PACKAGE_STRING"NSD 4.8.0" "NSD 4.8.0"
6#define PACKAGE_BUGREPORT"https://github.com/NLnetLabs/nsd/issues or nsd-bugs@nlnetlabs.nl" "https://github.com/NLnetLabs/nsd/issues or nsd-bugs@nlnetlabs.nl"
7#define PACKAGE_URL"" ""
8#define CONFCMDLINE"--prefix=/usr --localstatedir=/var --sysconfdir=/etc --with-ssl=/usr --with-user=_nsd --with-chroot=/var/nsd --with-configdir=/var/nsd/etc --with-pidfile= --with-zonesdir=/var/nsd/zones --with-dbfile= --with-zonelistfile=/var/nsd/db/zone.list --with-xfrdir=/var/nsd/run/xfr --with-xfrdfile=/var/nsd/run/xfrd.state --with-libevent=/usr --enable-ratelimit" "--prefix=/usr --localstatedir=/var --sysconfdir=/etc --with-ssl=/usr --with-user=_nsd --with-chroot=/var/nsd --with-configdir=/var/nsd/etc --with-pidfile= --with-zonesdir=/var/nsd/zones --with-dbfile= --with-zonelistfile=/var/nsd/db/zone.list --with-xfrdir=/var/nsd/run/xfr --with-xfrdfile=/var/nsd/run/xfrd.state --with-libevent=/usr --enable-ratelimit"
9#define STDC_HEADERS1 1
10#define HAVE_SYS_TYPES_H1 1
11#define HAVE_SYS_STAT_H1 1
12#define HAVE_STDLIB_H1 1
13#define HAVE_STRING_H1 1
14#define HAVE_MEMORY_H1 1
15#define HAVE_STRINGS_H1 1
16#define HAVE_INTTYPES_H1 1
17#define HAVE_STDINT_H1 1
18#define HAVE_UNISTD_H1 1
19#define __EXTENSIONS__1 1
20#define _ALL_SOURCE1 1
21#define _GNU_SOURCE1 1
22#define _POSIX_PTHREAD_SEMANTICS1 1
23#define _TANDEM_SOURCE1 1
24#define CONFIGDIR"/var/nsd/etc" "/var/nsd/etc"
25#define CONFIGFILE"/var/nsd/etc/nsd.conf" "/var/nsd/etc/nsd.conf"
26#define PIDFILE"" ""
27#define ZONESDIR"/var/nsd/zones" "/var/nsd/zones"
28#define XFRDFILE"/var/nsd/run/xfrd.state" "/var/nsd/run/xfrd.state"
29#define ZONELISTFILE"/var/nsd/db/zone.list" "/var/nsd/db/zone.list"
30#define XFRDIR"/var/nsd/run/xfr" "/var/nsd/run/xfr"
31#define NSD_START_PATH"/usr/sbin/nsd" "/usr/sbin/nsd"
32#define CHROOTDIR"/var/nsd" "/var/nsd"
33#define USER"_nsd" "_nsd"
34/* end confdefs.h. */
35#include <stdarg.h>
36#include <stdbool.h>
37#include <stdlib.h>
38#include <wchar.h>
39#include <stdio.h>
40
41// Check varargs macros. These examples are taken from C99 6.10.3.5.
42#define debug(...)fprintf ((&__sF[2]), ...) fprintf (stderr(&__sF[2]), __VA_ARGS__)
43#define showlist(...)puts ("...") puts (#__VA_ARGS__)
44#define report(test,...)((test) ? puts ("test") : printf (...)) ((test) ? puts (#test) : printf (__VA_ARGS__))
45static void
46test_varargs_macros (void)
47{
48 int x = 1234;
49 int y = 5678;
50 debug ("Flag")fprintf ((&__sF[2]), "Flag");
51 debug ("X = %d\n", x)fprintf ((&__sF[2]), "X = %d\n", x);
52 showlist (The first, second, and third items.)puts ("The first, second, and third items.");
53 report (x>y, "x is %d but y is %d", x, y)((x>y) ? puts ("x>y") : printf ("x is %d but y is %d", x
, y))
;
54}
55
56// Check long long types.
57#define BIG6418446744073709551615ull 18446744073709551615ull
58#define BIG324294967295ul 4294967295ul
59#define BIG_OK(18446744073709551615ull / 4294967295ul == 4294967297ull &&
18446744073709551615ull % 4294967295ul == 0)
(BIG6418446744073709551615ull / BIG324294967295ul == 4294967297ull && BIG6418446744073709551615ull % BIG324294967295ul == 0)
60#if !BIG_OK(18446744073709551615ull / 4294967295ul == 4294967297ull &&
18446744073709551615ull % 4294967295ul == 0)
61 your preprocessor is broken;
62#endif
63#if BIG_OK(18446744073709551615ull / 4294967295ul == 4294967297ull &&
18446744073709551615ull % 4294967295ul == 0)
64#else
65 your preprocessor is broken;
66#endif
67static long long int bignum = -9223372036854775807LL;
68static unsigned long long int ubignum = BIG6418446744073709551615ull;
69
70struct incomplete_array
71{
72 int datasize;
73 double data[];
74};
75
76struct named_init {
77 int number;
78 const wchar_t *name;
79 double average;
80};
81
82typedef const char *ccp;
83
84static inline int
85test_restrict (ccp restrict text)
86{
87 // See if C++-style comments work.
88 // Iterate through items via the restricted pointer.
89 // Also check for declarations in for loops.
90 for (unsigned int i = 0; *(text+i) != '\0'; ++i)
91 continue;
92 return 0;
93}
94
95// Check varargs and va_copy.
96static void
97test_varargs (const char *format, ...)
98{
99 va_list args;
100 va_start (args, format)__builtin_va_start((args), format);
101 va_list args_copy;
102 va_copy (args_copy, args)__builtin_va_copy(((args_copy)),((args)));
103
104 const char *str;
105 int number;
106 float fnumber;
107
108 while (*format)
109 {
110 switch (*format++)
111 {
112 case 's': // string
113 str = va_arg (args_copy, const char *)__builtin_va_arg((args_copy), const char *);
114 break;
115 case 'd': // int
116 number = va_arg (args_copy, int)__builtin_va_arg((args_copy), int);
Value stored to 'number' is never read
117 break;
118 case 'f': // float
119 fnumber = va_arg (args_copy, double)__builtin_va_arg((args_copy), double);
120 break;
121 default:
122 break;
123 }
124 }
125 va_end (args_copy)__builtin_va_end((args_copy));
126 va_end (args)__builtin_va_end((args));
127}
128
129int
130main ()
131{
132
133 // Check bool.
134 _Bool success = false0;
135
136 // Check restrict.
137 if (test_restrict ("String literal") == 0)
138 success = true1;
139 char *restrict newvar = "Another string";
140
141 // Check varargs.
142 test_varargs ("s, d' f .", "string", 65, 34.234);
143 test_varargs_macros ();
144
145 // Check flexible array members.
146 struct incomplete_array *ia =
147 malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
148 ia->datasize = 10;
149 for (int i = 0; i < ia->datasize; ++i)
150 ia->data[i] = i * 1.234;
151
152 // Check named initializers.
153 struct named_init ni = {
154 .number = 34,
155 .name = L"Test wide string",
156 .average = 543.34343,
157 };
158
159 ni.number = 58;
160
161 int dynamic_array[ni.number];
162 dynamic_array[ni.number - 1] = 543;
163
164 // work around unused variable warnings
165 return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
166 || dynamic_array[ni.number - 1] != 543);
167
168 ;
169 return 0;
170}