Bug Summary

File:root/firefox-clang/nsprpub/pr/src/md/unix/uxrng.c
Warning:line 122, column 5
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 Unified_c_external_nspr_pr1.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 -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/nspr/pr -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/nspr/pr -resource-dir /usr/lib/llvm-21/lib/clang/21 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D _GLIBCXX_ASSERTIONS -D DEBUG=1 -D _NSPR_BUILD_ -D LINUX -D HAVE_FCNTL_FILE_LOCKING -D HAVE_POINTER_LOCALTIME_R -D _GNU_SOURCE -D _PR_PTHREADS -I /root/firefox-clang/config/external/nspr/pr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/nspr/pr -I /root/firefox-clang/config/external/nspr -I /root/firefox-clang/nsprpub/pr/include -I /root/firefox-clang/nsprpub/pr/include/private -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-21/lib/clang/21/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 -O2 -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2025-06-27-100320-3286336-1 -x c Unified_c_external_nspr_pr1.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 "primpl.h"
7
8#include <string.h>
9#include <unistd.h>
10#include <errno(*__errno_location ()).h>
11#include <sys/time.h>
12
13#if defined(SOLARIS)
14
15static size_t GetHighResClock(void* buf, size_t maxbytes) {
16 hrtime_t t;
17 t = gethrtime();
18 if (t) {
19 return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
20 }
21 return 0;
22}
23
24#elif defined(HPUX)
25
26# ifdef __ia64
27# include <ia64/sys/inline.h>
28
29static size_t GetHighResClock(void* buf, size_t maxbytes) {
30 PRUint64 t;
31
32# ifdef __GNUC__4
33 __asm__ __volatile__("mov %0 = ar.itc" : "=r"(t));
34# else
35 t = _Asm_mov_from_ar(_AREG44);
36# endif
37 return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
38}
39# else
40static size_t GetHighResClock(void* buf, size_t maxbytes) {
41 extern int ret_cr16();
42 int cr16val;
43
44 cr16val = ret_cr16();
45 return (_pr_CopyLowBits(buf, maxbytes, &cr16val, sizeof(cr16val)));
46}
47# endif
48
49#elif defined(AIX)
50
51static size_t GetHighResClock(void* buf, size_t maxbytes) { return 0; }
52
53#elif (defined(LINUX1) || defined(FREEBSD) || defined(__FreeBSD_kernel__) || \
54 defined(NETBSD) || defined(__NetBSD_kernel__) || defined(OPENBSD) || \
55 defined(__GNU__))
56# include <sys/types.h>
57# include <sys/stat.h>
58# include <fcntl.h>
59
60static int fdDevURandom;
61static PRCallOnceType coOpenDevURandom;
62
63static PRStatus OpenDevURandom(void) {
64 fdDevURandom = open("/dev/urandom", O_RDONLY00);
65 return ((-1 == fdDevURandom) ? PR_FAILURE : PR_SUCCESS);
66} /* end OpenDevURandom() */
67
68static size_t GetDevURandom(void* buf, size_t size) {
69 int bytesIn;
70 int rc;
71
72 rc = PR_CallOnce(&coOpenDevURandom, OpenDevURandom);
73 if (PR_FAILURE == rc) {
74 _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ()));
75 return (0);
76 }
77
78 bytesIn = read(fdDevURandom, buf, size);
79 if (-1 == bytesIn) {
80 _PR_MD_MAP_READ_ERROR_MD_unix_map_read_error(errno(*__errno_location ()));
81 return (0);
82 }
83
84 return (bytesIn);
85} /* end GetDevURandom() */
86
87static size_t GetHighResClock(void* buf, size_t maxbytes) {
88 return (GetDevURandom(buf, maxbytes));
89}
90
91#elif defined(NTO) || defined(QNX) || defined(DARWIN) || defined(RISCOS)
92# include <sys/times.h>
93
94static size_t GetHighResClock(void* buf, size_t maxbytes) {
95 int ticks;
96 struct tms buffer;
97
98 ticks = times(&buffer);
99 return _pr_CopyLowBits(buf, maxbytes, &ticks, sizeof(ticks));
100}
101#else
102# error ! Platform undefined
103#endif /* defined(SOLARIS) */
104
105extern PRSize _PR_MD_GetRandomNoise(void* buf, PRSize size) {
106 struct timeval tv;
107 int n = 0;
108 int s;
109
110 n += GetHighResClock(buf, size);
111 size -= n;
112
113 GETTIMEOFDAY(&tv)gettimeofday((&tv), ((void*)0));
114
115 if (size > 0) {
116 s = _pr_CopyLowBits((char*)buf + n, size, &tv.tv_usec, sizeof(tv.tv_usec));
117 size -= s;
118 n += s;
119 }
120 if (size > 0) {
121 s = _pr_CopyLowBits((char*)buf + n, size, &tv.tv_sec, sizeof(tv.tv_usec));
122 size -= s;
Value stored to 'size' is never read
123 n += s;
124 }
125
126 return n;
127} /* end _PR_MD_GetRandomNoise() */