Bug Summary

File:pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/intrupt.c
Warning:line 169, column 5
Value stored to 'rv' 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 intrupt.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/intrupt.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 * File: intrupt.c
8 * Purpose: testing thread interrupts
9 */
10
11#include "plgetopt.h"
12#include "prcvar.h"
13#include "prerror.h"
14#include "prinit.h"
15#include "prinrval.h"
16#include "prio.h"
17#include "prlock.h"
18#include "prlog.h"
19#include "prthread.h"
20#include "prtypes.h"
21#include "prnetdb.h"
22
23#include <stdio.h>
24#include <string.h>
25
26#define DEFAULT_TCP_PORT12500 12500
27
28static PRLock *ml = NULL((void*)0);
29static PRCondVar *cv = NULL((void*)0);
30
31static PRBool passed = PR_TRUE1;
32static PRBool debug_mode = PR_FALSE0;
33static PRThreadScope thread_scope = PR_LOCAL_THREAD;
34
35static void PR_CALLBACK AbortCV(void *arg)
36{
37 PRStatus rv;
38 PRThread *me = PR_GetCurrentThread();
39
40 /* some other thread (main) is doing the interrupt */
41 PR_Lock(ml);
42 rv = PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT0xffffffffUL);
43 if (debug_mode) {
44 printf( "Expected interrupt on wait CV and ");
45 }
46 if (PR_FAILURE == rv)
47 {
48 if (PR_PENDING_INTERRUPT_ERROR(-5993L) == PR_GetError())
49 {
50 if (debug_mode) {
51 printf("got it\n");
52 }
53 }
54 else
55 {
56 if (debug_mode) {
57 printf("got random error\n");
58 }
59 passed = PR_FALSE0;
60 }
61 }
62 else
63 {
64 if (debug_mode) {
65 printf("got a successful completion\n");
66 }
67 passed = PR_FALSE0;
68 }
69
70 rv = PR_WaitCondVar(cv, 10);
71 if (debug_mode)
72 {
73 printf(
74 "Expected success on wait CV and %s\n",
75 (PR_SUCCESS == rv) ? "got it" : "failed");
76 }
77 passed = ((PR_TRUE1 == passed) && (PR_SUCCESS == rv)) ? PR_TRUE1 : PR_FALSE0;
78
79 /* interrupt myself, then clear */
80 PR_Interrupt(me);
81 PR_ClearInterrupt();
82 rv = PR_WaitCondVar(cv, 10);
83 if (debug_mode)
84 {
85 printf("Expected success on wait CV and ");
86 if (PR_FAILURE == rv)
87 {
88 printf(
89 "%s\n", (PR_PENDING_INTERRUPT_ERROR(-5993L) == PR_GetError()) ?
90 "got interrupted" : "a random failure");
91 }
92 printf("got it\n");
93 }
94 passed = ((PR_TRUE1 == passed) && (PR_SUCCESS == rv)) ? PR_TRUE1 : PR_FALSE0;
95
96 /* set, then wait - interrupt - then wait again */
97 PR_Interrupt(me);
98 rv = PR_WaitCondVar(cv, 10);
99 if (debug_mode) {
100 printf( "Expected interrupt on wait CV and ");
101 }
102 if (PR_FAILURE == rv)
103 {
104 if (PR_PENDING_INTERRUPT_ERROR(-5993L) == PR_GetError())
105 {
106 if (debug_mode) {
107 printf("got it\n");
108 }
109 }
110 else
111 {
112 if (debug_mode) {
113 printf("failed\n");
114 }
115 passed = PR_FALSE0;
116 }
117 }
118 else
119 {
120 if (debug_mode) {
121 printf("got a successful completion\n");
122 }
123 passed = PR_FALSE0;
124 }
125
126 rv = PR_WaitCondVar(cv, 10);
127 if (debug_mode)
128 {
129 printf(
130 "Expected success on wait CV and %s\n",
131 (PR_SUCCESS == rv) ? "got it" : "failed");
132 }
133 passed = ((PR_TRUE1 == passed) && (PR_SUCCESS == rv)) ? PR_TRUE1 : PR_FALSE0;
134
135 PR_Unlock(ml);
136
137} /* AbortCV */
138
139static void PR_CALLBACK AbortIO(void *arg)
140{
141 PRStatus rv;
142 PR_Sleep(PR_SecondsToInterval(2));
143 rv = PR_Interrupt((PRThread*)arg);
144 PR_ASSERT(PR_SUCCESS == rv)((PR_SUCCESS == rv)?((void)0):PR_Assert("PR_SUCCESS == rv","../../../pr/tests/intrupt.c"
,144))
;
145} /* AbortIO */
146
147static void PR_CALLBACK AbortJoin(void *arg)
148{
149} /* AbortJoin */
150
151static void setup_listen_socket(PRFileDesc **listner, PRNetAddr *netaddr)
152{
153 PRStatus rv;
154 PRInt16 port = DEFAULT_TCP_PORT12500;
155
156 *listner = PR_NewTCPSocket();
157 PR_ASSERT(*listner != NULL)((*listner != ((void*)0))?((void)0):PR_Assert("*listner != NULL"
,"../../../pr/tests/intrupt.c",157))
;
158 memset(netaddr, 0, sizeof(*netaddr));
159 (*netaddr).inet.ip = PR_htonl(PR_INADDR_ANY((in_addr_t) 0x00000000));
160 (*netaddr).inet.family = PR_AF_INET2;
161 do
162 {
163 (*netaddr).inet.port = PR_htons(port);
164 rv = PR_Bind(*listner, netaddr);
165 port += 1;
166 PR_ASSERT(port < (DEFAULT_TCP_PORT + 10))((port < (12500 + 10))?((void)0):PR_Assert("port < (DEFAULT_TCP_PORT + 10)"
,"../../../pr/tests/intrupt.c",166))
;
167 } while (PR_FAILURE == rv);
168
169 rv = PR_Listen(*listner, 5);
Value stored to 'rv' is never read
170
171 if (PR_GetSockName(*listner, netaddr) < 0) {
172 if (debug_mode) {
173 printf("intrupt: ERROR - PR_GetSockName failed\n");
174 }
175 passed = PR_FALSE0;
176 return;
177 }
178
179}
180
181static void PR_CALLBACK IntrBlock(void *arg)
182{
183 PRStatus rv;
184 PRNetAddr netaddr;
185 PRFileDesc *listner;
186
187 /* some other thread (main) is doing the interrupt */
188 /* block the interrupt */
189 PR_BlockInterrupt();
190 PR_Lock(ml);
191 rv = PR_WaitCondVar(cv, PR_SecondsToInterval(4));
192 PR_Unlock(ml);
193 if (debug_mode)
194 {
195 printf("Expected success on wait CV and ");
196 if (PR_FAILURE == rv)
197 {
198 printf(
199 "%s\n", (PR_PENDING_INTERRUPT_ERROR(-5993L) == PR_GetError()) ?
200 "got interrupted" : "got a random failure");
201 } else {
202 printf("got it\n");
203 }
204 }
205 passed = ((PR_TRUE1 == passed) && (PR_SUCCESS == rv)) ? PR_TRUE1 : PR_FALSE0;
206
207 setup_listen_socket(&listner, &netaddr);
208 PR_UnblockInterrupt();
209 if (PR_Accept(listner, &netaddr, PR_INTERVAL_NO_TIMEOUT0xffffffffUL) == NULL((void*)0))
210 {
211 PRInt32 error = PR_GetError();
212 if (debug_mode) {
213 printf("Expected interrupt on PR_Accept() and ");
214 }
215 if (PR_PENDING_INTERRUPT_ERROR(-5993L) == error)
216 {
217 if (debug_mode) {
218 printf("got it\n");
219 }
220 }
221 else
222 {
223 if (debug_mode) {
224 printf("failed\n");
225 }
226 passed = PR_FALSE0;
227 }
228 }
229 else
230 {
231 if (debug_mode) {
232 printf("Failed to interrupt PR_Accept()\n");
233 }
234 passed = PR_FALSE0;
235 }
236
237 (void)PR_Close(listner); listner = NULL((void*)0);
238} /* TestIntrBlock */
239
240void PR_CALLBACK Intrupt(void *arg)
241{
242 PRStatus rv;
243 PRNetAddr netaddr;
244 PRFileDesc *listner;
245 PRThread *abortCV, *abortIO, *abortJoin, *intrBlock;
246
247 ml = PR_NewLock();
248 cv = PR_NewCondVar(ml);
249
250 /* Part I */
251 if (debug_mode) {
252 printf("Part I\n");
253 }
254 abortCV = PR_CreateThread(
255 PR_USER_THREAD, AbortCV, 0, PR_PRIORITY_NORMAL,
256 thread_scope, PR_JOINABLE_THREAD, 0);
257
258 PR_Sleep(PR_SecondsToInterval(2));
259 rv = PR_Interrupt(abortCV);
260 PR_ASSERT(PR_SUCCESS == rv)((PR_SUCCESS == rv)?((void)0):PR_Assert("PR_SUCCESS == rv","../../../pr/tests/intrupt.c"
,260))
;
261 rv = PR_JoinThread(abortCV);
262 PR_ASSERT(PR_SUCCESS == rv)((PR_SUCCESS == rv)?((void)0):PR_Assert("PR_SUCCESS == rv","../../../pr/tests/intrupt.c"
,262))
;
263
264 /* Part II */
265 if (debug_mode) {
266 printf("Part II\n");
267 }
268 abortJoin = PR_CreateThread(
269 PR_USER_THREAD, AbortJoin, 0, PR_PRIORITY_NORMAL,
270 thread_scope, PR_JOINABLE_THREAD, 0);
271 PR_Sleep(PR_SecondsToInterval(2));
272 if (debug_mode) {
273 printf("Expecting to interrupt an exited thread ");
274 }
275 rv = PR_Interrupt(abortJoin);
276 PR_ASSERT(PR_SUCCESS == rv)((PR_SUCCESS == rv)?((void)0):PR_Assert("PR_SUCCESS == rv","../../../pr/tests/intrupt.c"
,276))
;
277 rv = PR_JoinThread(abortJoin);
278 PR_ASSERT(PR_SUCCESS == rv)((PR_SUCCESS == rv)?((void)0):PR_Assert("PR_SUCCESS == rv","../../../pr/tests/intrupt.c"
,278))
;
279 if (debug_mode) {
280 printf("and succeeded\n");
281 }
282
283 /* Part III */
284 if (debug_mode) {
285 printf("Part III\n");
286 }
287 setup_listen_socket(&listner, &netaddr);
288 abortIO = PR_CreateThread(
289 PR_USER_THREAD, AbortIO, PR_GetCurrentThread(), PR_PRIORITY_NORMAL,
290 thread_scope, PR_JOINABLE_THREAD, 0);
291
292 if (PR_Accept(listner, &netaddr, PR_INTERVAL_NO_TIMEOUT0xffffffffUL) == NULL((void*)0))
293 {
294 PRInt32 error = PR_GetError();
295 if (debug_mode) {
296 printf("Expected interrupt on PR_Accept() and ");
297 }
298 if (PR_PENDING_INTERRUPT_ERROR(-5993L) == error)
299 {
300 if (debug_mode) {
301 printf("got it\n");
302 }
303 }
304 else
305 {
306 if (debug_mode) {
307 printf("failed\n");
308 }
309 passed = PR_FALSE0;
310 }
311 }
312 else
313 {
314 if (debug_mode) {
315 printf("Failed to interrupt PR_Accept()\n");
316 }
317 passed = PR_FALSE0;
318 }
319
320 (void)PR_Close(listner); listner = NULL((void*)0);
321
322 rv = PR_JoinThread(abortIO);
323 PR_ASSERT(PR_SUCCESS == rv)((PR_SUCCESS == rv)?((void)0):PR_Assert("PR_SUCCESS == rv","../../../pr/tests/intrupt.c"
,323))
;
324 /* Part VI */
325 if (debug_mode) {
326 printf("Part VI\n");
327 }
328 intrBlock = PR_CreateThread(
329 PR_USER_THREAD, IntrBlock, 0, PR_PRIORITY_NORMAL,
330 thread_scope, PR_JOINABLE_THREAD, 0);
331
332 PR_Sleep(PR_SecondsToInterval(2));
333 rv = PR_Interrupt(intrBlock);
334 PR_ASSERT(PR_SUCCESS == rv)((PR_SUCCESS == rv)?((void)0):PR_Assert("PR_SUCCESS == rv","../../../pr/tests/intrupt.c"
,334))
;
335 rv = PR_JoinThread(intrBlock);
336 PR_ASSERT(PR_SUCCESS == rv)((PR_SUCCESS == rv)?((void)0):PR_Assert("PR_SUCCESS == rv","../../../pr/tests/intrupt.c"
,336))
;
337
338 PR_DestroyCondVar(cv);
339 PR_DestroyLock(ml);
340} /* Intrupt */
341
342int main(int argc, char **argv)
343{
344 PRThread *intrupt;
345 PLOptStatus os;
346 PLOptState *opt = PL_CreateOptState(argc, argv, "dG");
347 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
348 {
349 if (PL_OPT_BAD == os) {
350 continue;
351 }
352 switch (opt->option)
353 {
354 case 'd': /* debug mode */
355 debug_mode = PR_TRUE1;
356 break;
357 case 'G': /* use global threads */
358 thread_scope = PR_GLOBAL_THREAD;
359 break;
360 }
361 }
362 PL_DestroyOptState(opt);
363 PR_STDIO_INIT();
364 intrupt = PR_CreateThread(
365 PR_USER_THREAD, Intrupt, NULL((void*)0), PR_PRIORITY_NORMAL,
366 thread_scope, PR_JOINABLE_THREAD, 0);
367 if (intrupt == NULL((void*)0)) {
368 fprintf(stderrstderr, "cannot create thread\n");
369 passed = PR_FALSE0;
370 } else {
371 PRStatus rv;
372 rv = PR_JoinThread(intrupt);
373 PR_ASSERT(rv == PR_SUCCESS)((rv == PR_SUCCESS)?((void)0):PR_Assert("rv == PR_SUCCESS","../../../pr/tests/intrupt.c"
,373))
;
374 }
375 printf("%s\n", ((passed) ? "PASSED" : "FAILED"));
376 return ((passed) ? 0 : 1);
377} /* main */
378
379/* intrupt.c */