Bug Summary

File:pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/src/md/unix/../../../../../pr/src/md/unix/uxrng.c
Warning:line 142, column 9
Value stored to 'size' 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 uxrng.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/src/md/unix -fcoverage-compilation-dir=/var/lib/jenkins/workspace/nss-scan-build/nspr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/src/md/unix -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 -D _NSPR_BUILD_ -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/src/md/unix/uxrng.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#include "primpl.h"
8
9#include <string.h>
10#include <unistd.h>
11#include <errno(*__errno_location ()).h>
12#include <sys/time.h>
13
14
15#if defined(SOLARIS)
16
17static size_t
18GetHighResClock(void *buf, size_t maxbytes)
19{
20 hrtime_t t;
21 t = gethrtime();
22 if (t) {
23 return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
24 }
25 return 0;
26}
27
28#elif defined(HPUX)
29
30#ifdef __ia64
31#include <ia64/sys/inline.h>
32
33static size_t
34GetHighResClock(void *buf, size_t maxbytes)
35{
36 PRUint64 t;
37
38#ifdef __GNUC__4
39 __asm__ __volatile__("mov %0 = ar.itc" : "=r" (t));
40#else
41 t = _Asm_mov_from_ar(_AREG44);
42#endif
43 return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
44}
45#else
46static size_t
47GetHighResClock(void *buf, size_t maxbytes)
48{
49 extern int ret_cr16();
50 int cr16val;
51
52 cr16val = ret_cr16();
53 return(_pr_CopyLowBits(buf, maxbytes, &cr16val, sizeof(cr16val)));
54}
55#endif
56
57#elif defined(AIX)
58
59static size_t
60GetHighResClock(void *buf, size_t maxbytes)
61{
62 return 0;
63}
64
65#elif (defined(LINUX1) || defined(FREEBSD) || defined(__FreeBSD_kernel__) \
66 || defined(NETBSD) || defined(__NetBSD_kernel__) || defined(OPENBSD) \
67 || defined(__GNU__))
68#include <sys/types.h>
69#include <sys/stat.h>
70#include <fcntl.h>
71
72static int fdDevURandom;
73static PRCallOnceType coOpenDevURandom;
74
75static PRStatus OpenDevURandom( void )
76{
77 fdDevURandom = open( "/dev/urandom", O_RDONLY00 );
78 return((-1 == fdDevURandom)? PR_FAILURE : PR_SUCCESS );
79} /* end OpenDevURandom() */
80
81static size_t GetDevURandom( void *buf, size_t size )
82{
83 int bytesIn;
84 int rc;
85
86 rc = PR_CallOnce( &coOpenDevURandom, OpenDevURandom );
87 if ( PR_FAILURE == rc ) {
88 _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error( errno(*__errno_location ()) );
89 return(0);
90 }
91
92 bytesIn = read( fdDevURandom, buf, size );
93 if ( -1 == bytesIn ) {
94 _PR_MD_MAP_READ_ERROR_MD_unix_map_read_error( errno(*__errno_location ()) );
95 return(0);
96 }
97
98 return( bytesIn );
99} /* end GetDevURandom() */
100
101static size_t
102GetHighResClock(void *buf, size_t maxbytes)
103{
104 return(GetDevURandom( buf, maxbytes ));
105}
106
107#elif defined(SCO) || defined(UNIXWARE) || defined(BSDI) || defined(NTO) \
108 || defined(QNX) || defined(DARWIN) || defined(RISCOS)
109#include <sys/times.h>
110
111static size_t
112GetHighResClock(void *buf, size_t maxbytes)
113{
114 int ticks;
115 struct tms buffer;
116
117 ticks=times(&buffer);
118 return _pr_CopyLowBits(buf, maxbytes, &ticks, sizeof(ticks));
119}
120#else
121#error! Platform undefined
122#endif /* defined(SOLARIS) */
123
124extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
125{
126 struct timeval tv;
127 int n = 0;
128 int s;
129
130 n += GetHighResClock(buf, size);
131 size -= n;
132
133 GETTIMEOFDAY(&tv)gettimeofday((&tv), ((void*)0));
134
135 if ( size > 0 ) {
136 s = _pr_CopyLowBits((char*)buf+n, size, &tv.tv_usec, sizeof(tv.tv_usec));
137 size -= s;
138 n += s;
139 }
140 if ( size > 0 ) {
141 s = _pr_CopyLowBits((char*)buf+n, size, &tv.tv_sec, sizeof(tv.tv_usec));
142 size -= s;
Value stored to 'size' is never read
143 n += s;
144 }
145
146 return n;
147} /* end _PR_MD_GetRandomNoise() */