Bug Summary

File:pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/dtoa.c
Warning:line 185, column 5
Value stored to 'num1' 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 dtoa.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 -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -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=/var/lib/jenkins/workspace/nss-scan-build/nspr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests -fcoverage-compilation-dir=/var/lib/jenkins/workspace/nss-scan-build/nspr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests -resource-dir /usr/lib/llvm-18/lib/clang/18 -U NDEBUG -D DEBUG_jenkins -D PACKAGE_NAME="" -D PACKAGE_TARNAME="" -D PACKAGE_VERSION="" -D PACKAGE_STRING="" -D PACKAGE_BUGREPORT="" -D PACKAGE_URL="" -D DEBUG=1 -D HAVE_VISIBILITY_HIDDEN_ATTRIBUTE=1 -D HAVE_VISIBILITY_PRAGMA=1 -D XP_UNIX=1 -D _GNU_SOURCE=1 -D HAVE_FCNTL_FILE_LOCKING=1 -D HAVE_POINTER_LOCALTIME_R=1 -D LINUX=1 -D HAVE_DLADDR=1 -D HAVE_GETTID=1 -D HAVE_LCHOWN=1 -D HAVE_SETPRIORITY=1 -D HAVE_STRERROR=1 -D HAVE_SYSCALL=1 -D HAVE_SECURE_GETENV=1 -D _REENTRANT=1 -D FORCE_PR_LOG -D _PR_PTHREADS -U HAVE_CVAR_BUILT_ON_SEM -I /var/lib/jenkins/workspace/nss-scan-build/nss/../dist/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/include -I ../../../pr/include -I ../../../pr/include/private -internal-isystem /usr/lib/llvm-18/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 -ferror-limit 19 -fvisibility=hidden -fgnuc-version=4.2.1 -fno-inline -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-05-18-082241-28900-1 -x c ../../../pr/tests/dtoa.c
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6/******************************************************************************
7 *
8 * This file contains a test program for the function conversion functions
9 * for double precision code:
10 * PR_strtod
11 * PR_dtoa
12 * PR_cnvtf
13 *
14 * This file was ns/nspr/tests/dtoa.c, created by rrj on 1996/06/22.
15 *
16 *****************************************************************************/
17#include <stdio.h>
18#include <stdlib.h>
19#include <sys/types.h>
20#include <string.h>
21#include <locale.h>
22#include "prprf.h"
23#include "prdtoa.h"
24
25static int failed_already = 0;
26
27int main(int argc, char **argv)
28{
29 double num;
30 double num1;
31 double zero = 0.0;
32 char cnvt[50];
33 char *thousands;
34
35 num = 1e24;
36 num1 = PR_strtod("1e24",NULL((void*)0));
37 if(num1 != num) {
38 fprintf(stderrstderr,"Failed to convert numeric value %s\n","1e24");
39 failed_already = 1;
40 }
41
42 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
43 if(strcmp("1e+24",cnvt) != 0) {
44 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
45 failed_already = 1;
46 }
47
48 num = 0.001e7;
49 num1 = PR_strtod("0.001e7",NULL((void*)0));
50 if(num1 != num) {
51 fprintf(stderrstderr,"Failed to convert numeric value %s\n","0.001e7");
52 failed_already = 1;
53 }
54 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
55 if(strcmp("10000",cnvt) != 0) {
56 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
57 failed_already = 1;
58 }
59
60 num = 0.0000000000000753;
61 num1 = PR_strtod("0.0000000000000753",NULL((void*)0));
62 if(num1 != num) {
63 fprintf(stderrstderr,"Failed to convert numeric value %s\n",
64 "0.0000000000000753");
65 failed_already = 1;
66 }
67 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
68 if(strcmp("7.53e-14",cnvt) != 0) {
69 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
70 failed_already = 1;
71 }
72
73 num = 1.867e73;
74 num1 = PR_strtod("1.867e73",NULL((void*)0));
75 if(num1 != num) {
76 fprintf(stderrstderr,"Failed to convert numeric value %s\n","1.867e73");
77 failed_already = 1;
78 }
79 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
80 if(strcmp("1.867e+73",cnvt) != 0) {
81 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
82 failed_already = 1;
83 }
84
85
86 num = -1.867e73;
87 num1 = PR_strtod("-1.867e73",NULL((void*)0));
88 if(num1 != num) {
89 fprintf(stderrstderr,"Failed to convert numeric value %s\n","-1.867e73");
90 failed_already = 1;
91 }
92 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
93 if(strcmp("-1.867e+73",cnvt) != 0) {
94 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
95 failed_already = 1;
96 }
97
98 num = -1.867e-73;
99 num1 = PR_strtod("-1.867e-73",NULL((void*)0));
100 if(num1 != num) {
101 fprintf(stderrstderr,"Failed to convert numeric value %s\n","-1.867e-73");
102 failed_already = 1;
103 }
104
105 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
106 if(strcmp("-1.867e-73",cnvt) != 0) {
107 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
108 failed_already = 1;
109 }
110
111 /* Testing for infinity */
112 num = 1.0 / zero;
113 num1 = PR_strtod("1.867e765",NULL((void*)0));
114 if(num1 != num) {
115 fprintf(stderrstderr,"Failed to convert numeric value %s\n","1.867e765");
116 failed_already = 1;
117 }
118
119 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
120 if(strcmp("Infinity",cnvt) != 0) {
121 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
122 failed_already = 1;
123 }
124
125 num = -1.0 / zero;
126 num1 = PR_strtod("-1.867e765",NULL((void*)0));
127 if(num1 != num) {
128 fprintf(stderrstderr,"Failed to convert numeric value %s\n","-1.867e765");
129 failed_already = 1;
130 }
131
132 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
133 if(strcmp("-Infinity",cnvt) != 0) {
134 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
135 failed_already = 1;
136 }
137
138 /* Testing for NaN. PR_strtod can't parse "NaN" and "Infinity" */
139 num = zero / zero;
140
141 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
142 if(strcmp("NaN",cnvt) != 0) {
143 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
144 failed_already = 1;
145 }
146
147 num = - zero / zero;
148 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
149 if(strcmp("NaN",cnvt) != 0) {
150 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
151 failed_already = 1;
152 }
153
154 num = 1.0000000001e21;
155 num1 = PR_strtod("1.0000000001e21",NULL((void*)0));
156 if(num1 != num) {
157 fprintf(stderrstderr,"Failed to convert numeric value %s\n",
158 "1.0000000001e21");
159 failed_already = 1;
160 }
161
162 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
163 if(strcmp("1.0000000001e+21",cnvt) != 0) {
164 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
165 failed_already = 1;
166 }
167
168 num = -1.0000000001e-21;
169 num1 = PR_strtod("-1.0000000001e-21",NULL((void*)0));
170 if(num1 != num) {
171 fprintf(stderrstderr,"Failed to convert numeric value %s\n",
172 "-1.0000000001e-21");
173 failed_already = 1;
174 }
175 PR_cnvtf(cnvt,sizeof(cnvt),20,num);
176 if(strcmp("-1.0000000001e-21",cnvt) != 0) {
177 fprintf(stderrstderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
178 failed_already = 1;
179 }
180
181 /*
182 * Bug 414772: should not exit with "Zero passed to d2b" in debug
183 * build.
184 */
185 num1 = PR_strtod("4e-356",NULL((void*)0));
Value stored to 'num1' is never read
186
187 /*
188 * A very long input with ~384K digits.
189 * Bug 516396: Should not crash.
190 * Bug 521306: Should return 0 without converting the input.
191 */
192#define LENGTH(384 * 1024) (384 * 1024)
193 thousands = (char *)malloc(LENGTH(384 * 1024));
194 thousands[0] = '0';
195 thousands[1] = '.';
196 memset(&thousands[2], '1', LENGTH(384 * 1024) - 3);
197 thousands[LENGTH(384 * 1024) - 1] = '\0';
198 num = 0;
199 num1 = PR_strtod(thousands,NULL((void*)0));
200 free(thousands);
201 if(num1 != num) {
202 fprintf(stderrstderr,"Failed to convert numeric value %s\n",
203 "0.1111111111111111...");
204 failed_already = 1;
205 }
206
207 if (failed_already) {
208 printf("FAILED\n");
209 } else {
210 printf("PASSED\n");
211 }
212 return failed_already;
213}