Bug Summary

File:src/bigint_t.c
Warning:line 174, column 3
Value stored to 'n' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name bigint_t.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=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/kfp/aldor/aldor/aldor/src -fcoverage-compilation-dir=/home/kfp/aldor/aldor/aldor/src -resource-dir /usr/local/lib/clang/18 -D PACKAGE_NAME="aldor" -D PACKAGE_TARNAME="aldor" -D PACKAGE_VERSION="1.4.0" -D PACKAGE_STRING="aldor 1.4.0" -D PACKAGE_BUGREPORT="aldor@xinutec.org" -D PACKAGE_URL="" -D PACKAGE="aldor" -D VERSION="1.4.0" -D YYTEXT_POINTER=1 -D HAVE_STDIO_H=1 -D HAVE_STDLIB_H=1 -D HAVE_STRING_H=1 -D HAVE_INTTYPES_H=1 -D HAVE_STDINT_H=1 -D HAVE_STRINGS_H=1 -D HAVE_SYS_STAT_H=1 -D HAVE_SYS_TYPES_H=1 -D HAVE_UNISTD_H=1 -D STDC_HEADERS=1 -D HAVE_LIBREADLINE=1 -D HAVE_READLINE_READLINE_H=1 -D HAVE_READLINE_HISTORY=1 -D HAVE_READLINE_HISTORY_H=1 -D USE_GLOOP_SHELL=1 -D GENERATOR_COROUTINES=0 -D HAVE_DLFCN_H=1 -D LT_OBJDIR=".libs/" -I . -D VCSVERSION="2c53e759f1e00e345f8b172e7139debda72fda13" -D TEST_ALL -internal-isystem /usr/local/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-empty-body -Wno-enum-compare -Wno-missing-field-initializers -Wno-unused -Wno-unused-parameter -Wno-error=format -Wno-error=type-limits -Wno-error=strict-aliasing -Wno-sign-compare -Wno-error=shift-negative-value -Wno-error=clobbered -std=c99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2026-01-15-223856-845667-1 -x c bigint_t.c
1/*****************************************************************************
2 *
3 * bigint_t.c: Test big integer operations.
4 *
5 * Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).
6 *
7 ****************************************************************************/
8
9#if !defined(TEST_BIGINT) && !defined(TEST_ALL1)
10
11void testBigint(void) { }
12
13#else
14
15#include "axlgen.h"
16#include "bigint.h"
17#include "opsys.h"
18#include "strops.h"
19
20#define testBI_Limit(sizeof(testBI)/sizeof(testBI[0])) (sizeof(testBI)/sizeof(testBI[0]))
21#define ReallyBig303030 303030
22
23struct {
24 long n;
25 char *s;
26 BInt b;
27} testBI[] = {
28 { ReallyBig303030, "-3431053733523206522895434139"},
29 { ReallyBig303030, "-3431053733523205522895434139"},
30 { ReallyBig303030, "-8796093153280"},
31 { ReallyBig303030, "-4294967296"},
32 {-2147483647-1,"-2147483648"},
33 {-2147483647, "-2147483647"},
34 {-2000000000, "-2000000000"},
35 {-1073741824, "-1073741824"},
36 {-1073741823, "-1073741823"},
37 {-1073741822, "-1073741822"},
38 {-1000000000, "-1000000000"},
39 {-65537, "-65537" },
40 {-65536, "-65536" },
41 {-65535, "-65535" },
42 {-16385, "-16385" },
43 {-16384, "-16384" },
44 {-16383, "-16383" },
45 {-8193, "-8193" },
46 {-8192, "-8192" },
47 {-8191, "-8191" },
48 {-4096, "-4096" },
49 {-5, "-5" },
50 {-1, "-1" },
51 { 0, "0" },
52 { 1, "1" },
53 { 5, "5" },
54 { 4096, "4096" },
55 { 8191, "8191" },
56 { 8192, "8192" },
57 { 8193, "8193" },
58 { 16382, "16382" },
59 { 16383, "16383" },
60 { 16384, "16384" },
61 { 65534, "65534" },
62 { 65535, "65535" },
63 { 65536, "65536" },
64 { 1000000000, "1000000000" },
65 { 1073741822, "1073741822" },
66 { 1073741823, "1073741823" },
67 { 1073741824, "1073741824" },
68 { 2000000000, "2000000000" },
69 { 2147483646, "2147483646" },
70 { 2147483647, "2147483647" },
71 { ReallyBig303030, "4294967296"},
72 { ReallyBig303030, "8796093153280"},
73 { ReallyBig303030, "769169471909453733523206522895434140"},
74 { ReallyBig303030, "769169471909453734523206522895434140"}
75};
76
77void
78testBI_Start(char *what)
79{
80 printf("*** Test %s:\n", what);
81}
82
83void
84testBI_Bullet(int ix)
85{
86 long l = testBI[ix].n;
87
88 if (l == ReallyBig303030)
89 printf(" long: ");
90 else
91 printf(" %ld: ", l);
92}
93
94void
95testBI_End(void)
96{
97 printf("\n");
98}
99
100void
101testBigint(void)
102{
103 long n;
104 int i, j, k;
105 BInt a, b, c, d, t0, t1, t2;
106 String s;
107
108 testBI_Start("bintAlloc bintAllocPlaces bintFree");
109 for (i = 0; i < 65; i++) {
110 b = bintAlloc(i);
111 printf("%d bits. ", i);
112 bintFree(b);
113
114 b = bintAllocPlaces(i);
115 printf("%d places.\n", i);
116 bintFree(b);
117 }
118 testBI_End();
119
120 testBI_Start("bintFrString (+ iintTimesPlusI)");
121 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
122 testBI_Bullet(i);
123
124 s = testBI[i].s;
125 b = testBI[i].b = bintFrString(s);
126 bintPrint(osStdout, b);
127 printf("\n");
128 }
129 testBI_End();
130
131 testBI_Start("bintToString (+ iintDivideI)");
132 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
133 testBI_Bullet(i);
134
135 b = testBI[i].b;
136 s = bintToString(b);
137 printf("\"%s\"\n", s);
138 strFree(s);
139 }
140 testBI_End();
141
142 testBI_Start("bintPrint bintPrint16 bintPrint2");
143 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
144 testBI_Bullet(i);
145
146 b = testBI[i].b;
147 bintPrint(osStdout, b);
148 printf(" = ");
149 bintPrint16(osStdout, b);
150 printf(" =\n\t");
151 bintPrint2(osStdout, b);
152 printf("\n");
153 }
154 testBI_End();
155
156 testBI_Start("bintNew bintCopy");
157 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
158 testBI_Bullet(i);
159
160 b = testBI[i].b;
161 c = bintCopy(b);
162 bintPrint(osStdout, b);
163 printf(" = ");
164 bintPrint(osStdout, c);
165 printf("\n");
166 bintFree(c);
167 }
168 testBI_End();
169
170 testBI_Start("bintIsSmall bintSmall");
171 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
172 testBI_Bullet(i);
173
174 n = testBI[i].n;
Value stored to 'n' is never read
175 b = testBI[i].b;
176 if (bintIsSmall(b))
177 printf("small = %ld\n", bintSmall(b));
178 else
179 printf("not small\n");
180 }
181 testBI_End();
182
183 testBI_Start("xintStoreI xintStore xintImmedIfCan");
184 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
185 n = testBI[i].n;
186 if (n == ReallyBig303030) continue;
187 testBI_Bullet(i);
188
189 printf("\n");
190
191 printf(" N ");
192 a = xintStoreI(n);
193 bintPrint2(osStdout, a);
194 printf("\n");
195
196 b = xintImmedIfCan(a);
197 printf(" I ");
198 bintPrint2(osStdout, b);
199 printf("\n");
200 bintFree(b);
201
202 printf(" S ");
203 a = bintNew(n);
204 b = xintStore(a);
205 bintPrint2(osStdout, b);
206 printf("\n");
207 bintFree(b);
208 }
209 testBI_End();
210
211 testBI_Start("xintCopyInI");
212 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
213 n = testBI[i].n;
214 if (n == ReallyBig303030) continue;
215 testBI_Bullet(i);
216
217 b = bintAlloc(30);
218 b = xintCopyInI(b, n);
219 bintPrint2(osStdout, b);
220 printf("\n");
221 bintFree(b);
222 }
223 testBI_End();
224
225 testBI_Start("xintNeeds");
226 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
227 testBI_Bullet(i);
228
229 b = bintCopy(testBI[i].b);
230 printf("\n");
231 for (j = 0; j <= 126; j += 21) {
232 printf(" needs %3d: ", j);
233 b = xintNeeds(b, j);
234 bintPrint2(osStdout, b);
235 printf("\n");
236 }
237 bintFree(b);
238 }
239 testBI_End();
240
241 testBI_Start("bint0 bint1");
242 printf(" 0: "); bintPrint(osStdout, bint0); printf("\n");
243 printf(" 1: "); bintPrint(osStdout, bint1); printf("\n");
244 testBI_End();
245
246 testBI_Start("bintIsNeg bintIsZero bintIsPos");
247 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
248 testBI_Bullet(i);
249
250 b = testBI[i].b;
251 if (bintIsNeg(b)) printf("neg ");
252 if (bintIsZero(b)) printf("zero ");
253 if (bintIsPos(b)) printf("pos ");
254 printf("\n");
255 }
256 testBI_End();
257
258 testBI_Start("bintEQ");
259 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
260 a = testBI[i].b;
261 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
262 b = testBI[j].b;
263 printf("%s", bintEQ(a,b)?"T":"-");
264 }
265 printf("\n");
266 }
267 testBI_End();
268
269 testBI_Start("bintNE");
270 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
271 a = testBI[i].b;
272 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
273 b = testBI[j].b;
274 printf("%s", bintNE(a,b)(!bintEQ(a,b))?"T":"-");
275 }
276 printf("\n");
277 }
278 testBI_End();
279
280 testBI_Start("bintLT");
281 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
282 a = testBI[i].b;
283 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
284 b = testBI[j].b;
285 printf("%s", bintLT(a,b)?"T":"-");
286 }
287 printf("\n");
288 }
289 testBI_End();
290
291 testBI_Start("bintLE");
292 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
293 a = testBI[i].b;
294 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
295 b = testBI[j].b;
296 printf("%s", bintLE(a,b)(!bintGT(a,b))?"T":"-");
297 }
298 printf("\n");
299 }
300 testBI_End();
301
302 testBI_Start("bintGT");
303 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
304 a = testBI[i].b;
305 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
306 b = testBI[j].b;
307 printf("%s", bintGT(a,b)?"T":"-");
308 }
309 printf("\n");
310 }
311 testBI_End();
312
313 testBI_Start("bintGE");
314 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
315 a = testBI[i].b;
316 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
317 b = testBI[j].b;
318 printf("%s", bintGE(a,b)(!bintLT(a,b))?"T":"-");
319 }
320 printf("\n");
321 }
322 testBI_End();
323
324 testBI_Start("bintAbs");
325 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
326 testBI_Bullet(i);
327
328 b = testBI[i].b;
329 printf("abs(");
330 bintPrint(osStdout, b);
331
332 printf(") = ");
333 c = bintAbs(b);
334 bintPrint(osStdout, c);
335 printf("\n");
336
337 bintFree(c);
338 }
339 testBI_End();
340
341 testBI_Start("bintNegate");
342 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
343 testBI_Bullet(i);
344
345 b = testBI[i].b;
346 printf("negative ");
347 bintPrint(osStdout, b);
348
349 printf(" = ");
350 c = bintNegate(b);
351 bintPrint(osStdout, c);
352 printf("\n");
353
354 bintFree(c);
355 }
356 testBI_End();
357
358 testBI_Start("bintPlus");
359 d = bintNew(int0((int) 0));
360 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
361 b = testBI[i].b;
362 t1 = d;
363 d = bintPlus(b, d);
364 bintFree(t1);
365 }
366 printf(" Sum is ");
367 bintPrint(osStdout, d);
368 printf("\n");
369
370 bintFree(d);
371 printf("\n");
372
373 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
374 a = testBI[i].b;
375 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
376 b = testBI[j].b;
377 c = bintPlus(a,b);
378
379 bintPrint(osStdout, a);
380 printf(" + ");
381 bintPrint(osStdout, b);
382 printf(" = ");
383 bintPrint(osStdout, c);
384 printf("\n");
385
386 bintFree(c);
387 }
388 }
389 printf("\n");
390
391 d = bintNew(int0((int) 0));
392 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
393 a = testBI[i].b;
394 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
395 b = testBI[j].b;
396
397 t1 = bintPlus(a,b);
398 t2 = d;
399 d = bintPlus(t1, d);
400 bintFree(t2);
401 bintFree(t1);
402 }
403 }
404 printf(" Sum of addition table is ");
405 bintPrint(osStdout, d);
406 printf("\n");
407 bintFree(d);
408 testBI_End();
409
410 testBI_Start("bintMinus");
411 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
412 a = testBI[i].b;
413 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
414 b = testBI[j].b;
415 c = bintMinus(a,b);
416
417 bintPrint(osStdout, a);
418 printf(" - ");
419 bintPrint(osStdout, b);
420 printf(" = ");
421 bintPrint(osStdout, c);
422 printf("\n");
423
424 bintFree(c);
425 }
426 }
427 printf("\n");
428 testBI_End();
429
430 testBI_Start("bintTimes");
431 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
432 a = testBI[i].b;
433 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
434 b = testBI[j].b;
435 c = bintTimes(a,b);
436
437 bintPrint(osStdout, a);
438 printf(" * ");
439 bintPrint(osStdout, b);
440 printf(" = ");
441 bintPrint(osStdout, c);
442 printf("\n");
443
444 bintFree(c);
445 }
446 }
447 testBI_End();
448
449 testBI_Start("bintDivide");
450 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
451 a = testBI[i].b;
452
453 for (j = 0; j < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); j++) {
454 b = testBI[j].b;
455
456 if (bintIsZero(b)) continue;
457
458 c = bintDivide(&d, a,b);
459
460 printf("[ ");
461 bintPrint(osStdout, a);
462 printf(" ] = [ ");
463 bintPrint(osStdout, b);
464 printf(" ] ");
465
466 printf("* ");
467 bintPrint(osStdout, c);
468 printf(" + ");
469 bintPrint(osStdout, d);
470
471 t0 = bintIsNeg(b) ? bintNegate(b) : bintCopy(b);
472 t1 = bintTimes(b, c);
473 t2 = bintPlus(t1, d);
474
475 if (bintNE(a, t2)(!bintEQ(a,t2))) {
476 printf(" ***** Bad Value ***** = ");
477 bintPrint(osStdout, t2);
478 }
479 if (bintIsNeg(d)) {
480 t0 = xintNegate(t0);
481 if (bintLE(d, t0)(!bintGT(d,t0)))
482 printf(" ***** Out of range ***** ");
483 }
484 else {
485 if (bintGE(d, t0)(!bintLT(d,t0)))
486 printf(" ***** Out of range ***** ");
487 }
488
489 printf("\n");
490
491
492 bintFree(c);
493 bintFree(d);
494 bintFree(t0);
495 bintFree(t1);
496 bintFree(t2);
497 }
498 }
499 testBI_End();
500
501 testBI_Start("bintLength bintBit");
502 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
503 testBI_Bullet(i);
504
505 b = testBI[i].b;
506 k = bintLength(b);
507 printf("length = %d, ", k);
508 printf("leading bits = ");
509 for (j = k - 1; j >= 0 && j + 4 > k; j--)
510 printf(bintBit(b,j) ? "1 " : "0 ");
511 printf("\n");
512 }
513 testBI_End();
514
515 testBI_Start("bintShift (+iintShift)");
516 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) {
517 int jO, jF;
518
519 testBI_Bullet(i);
520
521 b = testBI[i].b;
522 bintPrint2(osStdout, b);
523 printf("\n");
524
525 jO = -(int)bintLength(b)-2;
526 jF = 35;
527 for (j = jO; j <= jF; j++) {
528 d = bintShift(b, j);
529 printf(" >>%4d: ", j);
530 bintPrint(osStdout, d);
531 bintFree(d);
532 printf("\n");
533 }
534 }
535 testBI_End();
536
537 for (i = 0; i < testBI_Limit(sizeof(testBI)/sizeof(testBI[0])); i++) bintFree(testBI[i].b);
538}
539
540#endif