Bug Summary

File:pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/many_cv.c
Warning:line 54, column 17
Value stored to 'stats' 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 many_cv.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/many_cv.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#include "prinit.h"
7#include "prprf.h"
8#include "prthread.h"
9#include "prcvar.h"
10#include "prlock.h"
11#include "prlog.h"
12#include "prmem.h"
13
14#include "primpl.h"
15
16#include "plgetopt.h"
17
18#include <stdlib.h>
19
20static PRInt32 RandomNum(void)
21{
22 PRInt32 ran = rand() >> 16;
23 return ran;
24} /* RandomNum */
25
26static void Help(void)
27{
28 PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
29 PR_fprintf(err, "many_cv usage: [-c n] [-l n] [-h]\n");
30 PR_fprintf(err, "\t-c n Number of conditions per lock (default: 10)\n");
31 PR_fprintf(err, "\t-l n Number of times to loop the test (default: 1)\n");
32 PR_fprintf(err, "\t-h This message and nothing else\n");
33} /* Help */
34
35static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
36{
37 PLOptStatus os;
38 PRIntn index, nl;
39 PRLock *ml = NULL((void*)0);
40 PRCondVar **cv = NULL((void*)0);
41 PRBool stats = PR_FALSE0;
42 PRIntn nc, loops = 1, cvs = 10;
43 PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
44 PLOptState *opt = PL_CreateOptState(argc, argv, "hsc:l:");
45
46 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
47 {
48 if (PL_OPT_BAD == os) {
49 continue;
50 }
51 switch (opt->option)
52 {
53 case 's': /* number of CVs to association with lock */
54 stats = PR_TRUE1;
Value stored to 'stats' is never read
55 break;
56 case 'c': /* number of CVs to association with lock */
57 cvs = atoi(opt->value);
58 break;
59 case 'l': /* number of times to run the tests */
60 loops = atoi(opt->value);
61 break;
62 case 'h': /* user wants some guidance */
63 default:
64 Help(); /* so give him an earful */
65 return 2; /* but not a lot else */
66 }
67 }
68 PL_DestroyOptState(opt);
69
70 PR_fprintf(err, "Settings\n");
71 PR_fprintf(err, "\tConditions / lock: %d\n", cvs);
72 PR_fprintf(err, "\tLoops to run test: %d\n", loops);
73
74 ml = PR_NewLock();
75 PR_ASSERT(NULL != ml)((((void*)0) != ml)?((void)0):PR_Assert("NULL != ml","../../../pr/tests/many_cv.c"
,75))
;
76
77 cv = (PRCondVar**)PR_CALLOC(sizeof(PRCondVar*) * cvs)(PR_Calloc(1, (sizeof(PRCondVar*) * cvs)));
78 PR_ASSERT(NULL != cv)((((void*)0) != cv)?((void)0):PR_Assert("NULL != cv","../../../pr/tests/many_cv.c"
,78))
;
79
80 for (index = 0; index < cvs; ++index)
81 {
82 cv[index] = PR_NewCondVar(ml);
83 PR_ASSERT(NULL != cv[index])((((void*)0) != cv[index])?((void)0):PR_Assert("NULL != cv[index]"
,"../../../pr/tests/many_cv.c",83))
;
84 }
85
86 for (index = 0; index < loops; ++index)
87 {
88 PR_Lock(ml);
89 for (nl = 0; nl < cvs; ++nl)
90 {
91 PRInt32 ran = RandomNum() % 8;
92 if (0 == ran) {
93 PR_NotifyAllCondVar(cv[nl]);
94 }
95 else for (nc = 0; nc < ran; ++nc) {
96 PR_NotifyCondVar(cv[nl]);
97 }
98 }
99 PR_Unlock(ml);
100 }
101
102 for (index = 0; index < cvs; ++index) {
103 PR_DestroyCondVar(cv[index]);
104 }
105
106 PR_DELETE(cv){ PR_Free(cv); (cv) = ((void*)0); };
107
108 PR_DestroyLock(ml);
109
110 printf("PASS\n");
111
112 PT_FPrintStats(err, "\nPThread Statistics\n");
113 return 0;
114}
115
116
117int main(int argc, char **argv)
118{
119 PRIntn rv;
120
121 PR_STDIO_INIT();
122 rv = PR_Initialize(RealMain, argc, argv, 0);
123 return rv;
124} /* main */