Bug Summary

File:pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/writev.c
Warning:line 164, column 17
Value stored to 'bytes' 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 writev.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/writev.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 "nspr.h"
7
8#include "plgetopt.h"
9
10#include <stdlib.h>
11#include <string.h>
12
13
14#ifndef IOV_MAX16
15#define IOV_MAX16 16
16#endif
17
18#ifdef DEBUG1
19#define PORT_INC_DO+100 +100
20#else
21#define PORT_INC_DO+100
22#endif
23#ifdef IS_64
24#define PORT_INC_3264+200 +200
25#else
26#define PORT_INC_3264+200
27#endif
28
29#define BASE_PORT9867 +100 +200 9867 PORT_INC_DO+100 PORT_INC_3264+200
30
31int PR_CALLBACK Writev(int argc, char **argv)
32{
33
34 PRStatus rv;
35 PRNetAddr serverAddr;
36 PRFileDesc *clientSock, *debug = NULL((void*)0);
37
38 char *buffer = NULL((void*)0);
39 PRIOVec *iov = NULL((void*)0);
40 PRBool passed = PR_TRUE1;
41 PRIntervalTime timein, elapsed, timeout;
42 PRIntervalTime tmo_min = 0x7fffffff, tmo_max = 0, tmo_elapsed = 0;
43 PRInt32 tmo_counted = 0, iov_index, loop, bytes, number_fragments;
44 PRInt32 message_length = 100, fragment_length = 100, messages = 100;
45 struct Descriptor {
46 PRInt32 length;
47 PRUint32 checksum;
48 } descriptor;
49
50 /*
51 * USAGE
52 * -h dns name of host serving the connection (default = self)
53 * -m number of messages to send (default = 100)
54 * -s size of each message (default = 100)
55 * -f size of each message fragment (default = 100)
56 */
57
58 PLOptStatus os;
59 PLOptState *opt = PL_CreateOptState(argc, argv, "dh:m:s:f:");
60
61 PR_STDIO_INIT();
62 rv = PR_InitializeNetAddr(PR_IpAddrLoopback, BASE_PORT9867 +100 +200, &serverAddr);
63 PR_ASSERT(PR_SUCCESS == rv)((PR_SUCCESS == rv)?((void)0):PR_Assert("PR_SUCCESS == rv","../../../pr/tests/writev.c"
,63))
;
64
65 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
66 {
67 if (PL_OPT_BAD == os) {
68 continue;
69 }
70 switch (opt->option)
71 {
72 case 'h': /* the remote host */
73 {
74 PRIntn es = 0;
75 PRHostEnt host;
76 char buffer[1024];
77 (void)PR_GetHostByName(opt->value, buffer, sizeof(buffer), &host);
78 es = PR_EnumerateHostEnt(es, &host, BASE_PORT9867 +100 +200, &serverAddr);
79 PR_ASSERT(es > 0)((es > 0)?((void)0):PR_Assert("es > 0","../../../pr/tests/writev.c"
,79))
;
80 }
81 break;
82 case 'd': /* debug mode */
83 debug = PR_GetSpecialFD(PR_StandardError);
84 break;
85 case 'm': /* number of messages to send */
86 messages = atoi(opt->value);
87 break;
88 case 's': /* total size of each message */
89 message_length = atoi(opt->value);
90 break;
91 case 'f': /* size of each message fragment */
92 fragment_length = atoi(opt->value);
93 break;
94 default:
95 break;
96 }
97 }
98 PL_DestroyOptState(opt);
99
100 buffer = (char*)malloc(message_length);
101
102 number_fragments = (message_length + fragment_length - 1) / fragment_length + 1;
103 while (IOV_MAX16 < number_fragments)
104 {
105 fragment_length = message_length / (IOV_MAX16 - 2);
106 number_fragments = (message_length + fragment_length - 1) /
107 fragment_length + 1;
108 if (NULL((void*)0) != debug) PR_fprintf(debug,
109 "Too many fragments - reset fragment length to %ld\n", fragment_length);
110 }
111 iov = (PRIOVec*)malloc(number_fragments * sizeof(PRIOVec));
112
113 iov[0].iov_base = (char*)&descriptor;
114 iov[0].iov_len = sizeof(descriptor);
115 for (iov_index = 1; iov_index < number_fragments; ++iov_index)
116 {
117 iov[iov_index].iov_base = buffer + (iov_index - 1) * fragment_length;
118 iov[iov_index].iov_len = fragment_length;
119 }
120
121 for (bytes = 0; bytes < message_length; ++bytes) {
122 buffer[bytes] = (char)bytes;
123 }
124
125 timeout = PR_SecondsToInterval(1);
126
127 for (loop = 0; loop < messages; ++loop)
128 {
129 if (NULL((void*)0) != debug) {
130 PR_fprintf(debug, "[%d]socket ... ", loop);
131 }
132 clientSock = PR_NewTCPSocket();
133 if (clientSock)
134 {
135 timein = PR_IntervalNow();
136 if (NULL((void*)0) != debug) {
137 PR_fprintf(debug, "connecting ... ");
138 }
139 rv = PR_Connect(clientSock, &serverAddr, timeout);
140 if (PR_SUCCESS == rv)
141 {
142 descriptor.checksum = 0;
143 descriptor.length = (loop < (messages - 1)) ? message_length : 0;
144 if (0 == descriptor.length) {
145 number_fragments = 1;
146 }
147 else
148 for (iov_index = 0; iov_index < descriptor.length; ++iov_index)
149 {
150 PRUint32 overflow = descriptor.checksum & 0x80000000;
151 descriptor.checksum = (descriptor.checksum << 1);
152 if (0x00000000 != overflow) {
153 descriptor.checksum += 1;
154 }
155 descriptor.checksum += buffer[iov_index];
156 }
157 if (NULL((void*)0) != debug) PR_fprintf(
158 debug, "sending %d bytes ... ", descriptor.length);
159
160 /* then, at the last moment ... */
161 descriptor.length = PR_ntohl(descriptor.length);
162 descriptor.checksum = PR_ntohl(descriptor.checksum);
163
164 bytes = PR_Writev(clientSock, iov, number_fragments, timeout);
Value stored to 'bytes' is never read
165 if (NULL((void*)0) != debug) {
166 PR_fprintf(debug, "closing ... ");
167 }
168 rv = PR_Shutdown(clientSock, PR_SHUTDOWN_BOTH);
169 rv = PR_Close(clientSock);
170 if (NULL((void*)0) != debug) PR_fprintf(
171 debug, "%s\n", ((PR_SUCCESS == rv) ? "good" : "bad"));
172 elapsed = PR_IntervalNow() - timein;
173 if (elapsed < tmo_min) {
174 tmo_min = elapsed;
175 }
176 else if (elapsed > tmo_max) {
177 tmo_max = elapsed;
178 }
179 tmo_elapsed += elapsed;
180 tmo_counted += 1;
181 }
182 else
183 {
184 if (NULL((void*)0) != debug) PR_fprintf(
185 debug, "failed - retrying (%d, %d)\n",
186 PR_GetError(), PR_GetOSError());
187 PR_Close(clientSock);
188 }
189 }
190 else if (NULL((void*)0) != debug)
191 {
192 PR_fprintf(debug, "unable to create client socket\n");
193 passed = PR_FALSE0;
194 }
195 }
196 if (NULL((void*)0) != debug) {
197 if (0 == tmo_counted) {
198 PR_fprintf(debug, "No connection made\n");
199 } else {
200 PR_fprintf(
201 debug, "\nTimings: %d [%d] %d (microseconds)\n",
202 PR_IntervalToMicroseconds(tmo_min),
203 PR_IntervalToMicroseconds(tmo_elapsed / tmo_counted),
204 PR_IntervalToMicroseconds(tmo_max));
205 }
206 }
207
208 PR_DELETE(buffer){ PR_Free(buffer); (buffer) = ((void*)0); };
209 PR_DELETE(iov){ PR_Free(iov); (iov) = ((void*)0); };
210
211 PR_fprintf(
212 PR_GetSpecialFD(PR_StandardError),
213 "%s\n", (passed) ? "PASSED" : "FAILED");
214 return (passed) ? 0 : 1;
215}
216
217int main(int argc, char **argv)
218{
219 return (PR_VersionCheck(PR_VERSION"4.36 Beta")) ?
220 PR_Initialize(Writev, argc, argv, 4) : -1;
221} /* main */
222
223/* writev.c */
224
225