Bug Summary

File:pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/poll_to.c
Warning:line 164, column 5
Value stored to 'other_pds' 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 poll_to.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/poll_to.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: prpoll_to.c
9**
10** Description: This program tests PR_Poll with sockets.
11** Timeout operation is tested
12**
13** Modification History:
14** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
15** The debug mode will print all of the printfs associated with this test.
16** The regress mode will be the default mode. Since the regress tool limits
17** the output to a one line status:PASS or FAIL,all of the printf statements
18** have been handled with an if (debug_mode) statement.
19** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
20** recognize the return code from tha main program.
21***********************************************************************/
22
23/***********************************************************************
24** Includes
25***********************************************************************/
26/* Used to get the command line option */
27#include "plgetopt.h"
28
29#include "prinit.h"
30#include "prio.h"
31#include "prlog.h"
32#include "prprf.h"
33#include "prnetdb.h"
34
35#include "private/pprio.h"
36
37#include <stdio.h>
38#include <string.h>
39#include <stdlib.h>
40
41PRIntn failed_already=0;
42PRIntn debug_mode;
43
44int main(int argc, char **argv)
45{
46 PRFileDesc *listenSock1 = NULL((void*)0), *listenSock2 = NULL((void*)0);
47 PRUint16 listenPort1, listenPort2;
48 PRNetAddr addr;
49 char buf[128];
50 PRPollDesc pds0[10], pds1[10], *pds, *other_pds;
51 PRIntn npds;
52 PRInt32 retVal;
53
54 /* The command line argument: -d is used to determine if the test is being run
55 in debug mode. The regress tool requires only one line output:PASS or FAIL.
56 All of the printfs associated with this test has been handled with a if (debug_mode)
57 test.
58 Usage: test_name -d
59 */
60 PLOptStatus os;
61 PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
62 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
63 {
64 if (PL_OPT_BAD == os) {
65 continue;
66 }
67 switch (opt->option)
68 {
69 case 'd': /* debug mode */
70 debug_mode = 1;
71 break;
72 default:
73 break;
74 }
75 }
76 PL_DestroyOptState(opt);
77
78 /* main test */
79
80 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
81 PR_STDIO_INIT();
82
83 if (debug_mode) {
84 printf("This program tests PR_Poll with sockets.\n");
85 printf("Timeout is tested.\n\n");
86 }
87
88 /* Create two listening sockets */
89 if ((listenSock1 = PR_NewTCPSocket()) == NULL((void*)0)) {
90 fprintf(stderrstderr, "Can't create a new TCP socket\n");
91 if (!debug_mode) {
92 failed_already=1;
93 }
94 goto exit_now;
95 }
96 memset(&addr, 0, sizeof(addr));
97 addr.inet.family = PR_AF_INET2;
98 addr.inet.ip = PR_htonl(PR_INADDR_ANY((in_addr_t) 0x00000000));
99 addr.inet.port = PR_htons(0);
100 if (PR_Bind(listenSock1, &addr) == PR_FAILURE) {
101 fprintf(stderrstderr, "Can't bind socket\n");
102 if (!debug_mode) {
103 failed_already=1;
104 }
105 goto exit_now;
106 }
107 if (PR_GetSockName(listenSock1, &addr) == PR_FAILURE) {
108 fprintf(stderrstderr, "PR_GetSockName failed\n");
109 if (!debug_mode) {
110 failed_already=1;
111 }
112 goto exit_now;
113 }
114 listenPort1 = PR_ntohs(addr.inet.port);
115 if (PR_Listen(listenSock1, 5) == PR_FAILURE) {
116 fprintf(stderrstderr, "Can't listen on a socket\n");
117 if (!debug_mode) {
118 failed_already=1;
119 }
120 goto exit_now;
121 }
122
123 if ((listenSock2 = PR_NewTCPSocket()) == NULL((void*)0)) {
124 fprintf(stderrstderr, "Can't create a new TCP socket\n");
125 if (!debug_mode) {
126 failed_already=1;
127 }
128 goto exit_now;
129 }
130 addr.inet.family = PR_AF_INET2;
131 addr.inet.ip = PR_htonl(PR_INADDR_ANY((in_addr_t) 0x00000000));
132 addr.inet.port = PR_htons(0);
133 if (PR_Bind(listenSock2, &addr) == PR_FAILURE) {
134 fprintf(stderrstderr, "Can't bind socket\n");
135 if (!debug_mode) {
136 failed_already=1;
137 }
138 goto exit_now;
139 }
140 if (PR_GetSockName(listenSock2, &addr) == PR_FAILURE) {
141 fprintf(stderrstderr, "PR_GetSockName failed\n");
142 if (!debug_mode) {
143 failed_already=1;
144 }
145 goto exit_now;
146 }
147 listenPort2 = PR_ntohs(addr.inet.port);
148 if (PR_Listen(listenSock2, 5) == PR_FAILURE) {
149 fprintf(stderrstderr, "Can't listen on a socket\n");
150 if (!debug_mode) {
151 failed_already=1;
152 }
153 goto exit_now;
154 }
155 PR_snprintf(buf, sizeof(buf),
156 "The server thread is listening on ports %hu and %hu\n\n",
157 listenPort1, listenPort2);
158 if (debug_mode) {
159 printf("%s", buf);
160 }
161
162 /* Set up the poll descriptor array */
163 pds = pds0;
164 other_pds = pds1;
Value stored to 'other_pds' is never read
165 memset(pds, 0, sizeof(pds));
166 pds[0].fd = listenSock1;
167 pds[0].in_flags = PR_POLL_READ0x1;
168 pds[1].fd = listenSock2;
169 pds[1].in_flags = PR_POLL_READ0x1;
170 npds = 2;
171
172 /* Testing timeout */
173 if (debug_mode) {
174 printf("PR_Poll should time out in 5 seconds\n");
175 }
176 retVal = PR_Poll(pds, npds, PR_SecondsToInterval(5));
177 if (retVal != 0) {
178 PR_snprintf(buf, sizeof(buf),
179 "PR_Poll should time out and return 0, but it returns %ld\n",
180 retVal);
181 fprintf(stderrstderr, "%s", buf);
182 if (!debug_mode) {
183 failed_already=1;
184 }
185 goto exit_now;
186 }
187 if (debug_mode) {
188 printf("PR_Poll timed out. Test passed.\n\n");
189 }
190
191exit_now:
192
193 if (listenSock1) {
194 PR_Close(listenSock1);
195 }
196 if (listenSock2) {
197 PR_Close(listenSock2);
198 }
199
200 PR_Cleanup();
201
202 if(failed_already) {
203 return 1;
204 }
205 else {
206 return 0;
207 }
208
209}