Bug Summary

File:pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/sem.c
Warning:line 191, column 5
Value stored to 'r' 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 sem.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/sem.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** Name: sem.c
9**
10** Description: Tests Semaphonre functions.
11**
12** Modification History:
13** 20-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
14** The debug mode will print all of the printfs associated with this test.
15** The regress mode will be the default mode. Since the regress tool limits
16** the output to a one line status:PASS or FAIL,all of the printf statements
17** have been handled with an if (debug_mode) statement.
18** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
19** recognize the return code from tha main program.
20***********************************************************************/
21
22/***********************************************************************
23** Includes
24***********************************************************************/
25/* Used to get the command line option */
26#include "plgetopt.h"
27
28#include "nspr.h"
29#include "prpriv.h"
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34
35PRIntn failed_already=0;
36PRIntn debug_mode;
37
38/*
39 Since we don't have stdin, stdout everywhere, we will fake
40 it with our in-memory buffers called stdin and stdout.
41*/
42
43#define SBSIZE1024 1024
44
45#include "obsolete/prsem.h"
46
47static char stdinBuf[SBSIZE1024];
48static char stdoutBuf[SBSIZE1024];
49
50static PRUintn stdinBufIdx = 0;
51static PRUintn stdoutBufIdx = 0;
52static PRStatus finalResult = PR_SUCCESS;
53
54
55static size_t dread (PRUintn device, char *buf, size_t bufSize)
56{
57 PRUintn i;
58
59 /* during first read call, initialize the stdinBuf buffer*/
60 if (stdinBufIdx == 0) {
61 for (i=0; i<SBSIZE1024; i++) {
62 stdinBuf[i] = i;
63 }
64 }
65
66 /* now copy data from stdinBuf to the given buffer upto bufSize */
67 for (i=0; i<bufSize; i++) {
68 if (stdinBufIdx == SBSIZE1024) {
69 break;
70 }
71 buf[i] = stdinBuf[stdinBufIdx++];
72 }
73
74 return i;
75}
76
77static size_t dwrite (PRUintn device, char *buf, size_t bufSize)
78{
79 PRUintn i, j;
80
81 /* copy data from the given buffer upto bufSize to stdoutBuf */
82 for (i=0; i<bufSize; i++) {
83 if (stdoutBufIdx == SBSIZE1024) {
84 break;
85 }
86 stdoutBuf[stdoutBufIdx++] = buf[i];
87 }
88
89 /* during last write call, compare the two buffers */
90 if (stdoutBufIdx == SBSIZE1024)
91 for (j=0; j<SBSIZE1024; j++)
92 if (stdinBuf[j] != stdoutBuf[j]) {
93 if (debug_mode) {
94 printf("data mismatch for index= %d \n", j);
95 }
96 finalResult = PR_FAILURE;
97 }
98
99 return i;
100}
101
102/*------------------ Following is the real test program ---------*/
103/*
104 Program to copy standard input to standard output. The program
105 uses two threads. One reads the input and puts the data in a
106 double buffer. The other reads the buffer contents and writes
107 it to standard output.
108*/
109
110PRSemaphore *emptyBufs; /* number of empty buffers */
111PRSemaphore *fullBufs; /* number of buffers that are full */
112
113#define BSIZE100 100
114
115struct {
116 char data[BSIZE100];
117 PRUintn nbytes; /* number of bytes in this buffer */
118} buf[2];
119
120static void PR_CALLBACK reader(void *arg)
121{
122 PRUintn i = 0;
123 size_t nbytes;
124
125 do {
126 (void) PR_WaitSem(emptyBufs);
127 nbytes = dread(0, buf[i].data, BSIZE100);
128 buf[i].nbytes = nbytes;
129 PR_PostSem(fullBufs);
130 i = (i + 1) % 2;
131 } while (nbytes > 0);
132}
133
134static void writer(void)
135{
136 PRUintn i = 0;
137 size_t nbytes;
138
139 do {
140 (void) PR_WaitSem(fullBufs);
141 nbytes = buf[i].nbytes;
142 if (nbytes > 0) {
143 nbytes = dwrite(1, buf[i].data, nbytes);
144 PR_PostSem(emptyBufs);
145 i = (i + 1) % 2;
146 }
147 } while (nbytes > 0);
148}
149
150int main(int argc, char **argv)
151{
152 PRThread *r;
153
154 PR_STDIO_INIT();
155 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
156
157 {
158 /* The command line argument: -d is used to determine if the test is being run
159 in debug mode. The regress tool requires only one line output:PASS or FAIL.
160 All of the printfs associated with this test has been handled with a if (debug_mode)
161 test.
162 Usage: test_name -d
163 */
164 PLOptStatus os;
165 PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
166 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
167 {
168 if (PL_OPT_BAD == os) {
169 continue;
170 }
171 switch (opt->option)
172 {
173 case 'd': /* debug mode */
174 debug_mode = 1;
175 break;
176 default:
177 break;
178 }
179 }
180 PL_DestroyOptState(opt);
181 }
182
183 /* main test */
184
185 emptyBufs = PR_NewSem(2); /* two empty buffers */
186
187 fullBufs = PR_NewSem(0); /* zero full buffers */
188
189 /* create the reader thread */
190
191 r = PR_CreateThread(PR_USER_THREAD,
Value stored to 'r' is never read
192 reader, 0,
193 PR_PRIORITY_NORMAL,
194 PR_LOCAL_THREAD,
195 PR_UNJOINABLE_THREAD,
196 0);
197
198 /* Do the writer operation in this thread */
199 writer();
200
201 PR_DestroySem(emptyBufs);
202 PR_DestroySem(fullBufs);
203
204 if (finalResult == PR_SUCCESS) {
205 if (debug_mode) {
206 printf("sem Test Passed.\n");
207 }
208 }
209 else {
210 if (debug_mode) {
211 printf("sem Test Failed.\n");
212 }
213 failed_already=1;
214 }
215 PR_Cleanup();
216 if(failed_already) {
217 return 1;
218 }
219 else {
220 return 0;
221 }
222}