Bug Summary

File:.build-ci/../shared/test/test-progress-util.c
Warning:line 27, column 6
Value of 'errno' was not checked and may be overwritten by function 'fread'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test-progress-util.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 -mrelocation-model static -mframe-pointer=none -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=/__w/nvme-cli/nvme-cli/.build-ci -fcoverage-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -resource-dir /usr/bin/../lib/clang/22 -include /__w/nvme-cli/nvme-cli/.build-ci/nvme-config.h -I shared/test/test-progress-util.p -I shared/test -I ../shared/test -I . -I .. -I shared -I ../shared -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -U NDEBUG -internal-isystem /usr/bin/../lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=gnu99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-opt-analyze-headers -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /__w/nvme-cli/nvme-cli/.build-ci/scan-results/2026-08-08-045408-589-1 -x c ../shared/test/test-progress-util.c
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * This file is part of nvme-cli.
4 */
5#include <stdbool.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9
10#include <progress-util.h>
11
12static bool_Bool check_bool(const char *name, bool_Bool got)
13{
14 printf(" - %s [%s]\n", name, got ? "PASS" : "FAIL");
15 return got;
16}
17
18static char *capture(void (*fn)(FILE *stream))
19{
20 static char buf[512];
21 FILE *stream = tmpfile();
22 size_t n;
23
24 memset(buf, 0, sizeof(buf));
25 fn(stream);
26 rewind(stream);
2
After calling 'rewind' reading 'errno' is required to find out if the call has failed
27 n = fread(buf, 1, sizeof(buf) - 1, stream);
3
Value of 'errno' was not checked and may be overwritten by function 'fread'
28 buf[n] = '\0';
29 fclose(stream);
30
31 return buf;
32}
33
34static void run_zero(FILE *stream)
35{
36 shr_spinner("Task", 0.0, stream);
37}
38
39static void run_half(FILE *stream)
40{
41 shr_spinner("Task", 0.5, stream);
42}
43
44static void run_full(FILE *stream)
45{
46 shr_spinner("Task", 1.0, stream);
47}
48
49static void run_clamped(FILE *stream)
50{
51 shr_spinner("Task", 5.0, stream);
52}
53
54int main(void)
55{
56 bool_Bool pass = true1;
57 char *out;
58
59 printf("test_spinner:\n");
60
61 out = capture(run_zero);
1
Calling 'capture'
62 pass &= check_bool("0% output contains the label", strstr(out, "Task")_Generic (0 ? (out) : (void *) 1, const void *: (const char *
) (strstr (out, "Task")), default: strstr (out, "Task"))
!= NULL((void*)0));
63 pass &= check_bool("0% output shows 0%", strstr(out, "0%")_Generic (0 ? (out) : (void *) 1, const void *: (const char *
) (strstr (out, "0%")), default: strstr (out, "0%"))
!= NULL((void*)0));
64
65 out = capture(run_half);
66 pass &= check_bool("50% output shows 50%", strstr(out, "50%")_Generic (0 ? (out) : (void *) 1, const void *: (const char *
) (strstr (out, "50%")), default: strstr (out, "50%"))
!= NULL((void*)0));
67
68 out = capture(run_full);
69 pass &= check_bool("100% output shows 100%", strstr(out, "100%")_Generic (0 ? (out) : (void *) 1, const void *: (const char *
) (strstr (out, "100%")), default: strstr (out, "100%"))
!= NULL((void*)0));
70
71 out = capture(run_clamped);
72 pass &= check_bool("percent > 1.0 is clamped to 100%", strstr(out, "100%")_Generic (0 ? (out) : (void *) 1, const void *: (const char *
) (strstr (out, "100%")), default: strstr (out, "100%"))
!= NULL((void*)0));
73
74 fflush(stdoutstdout);
75 exit(pass ? EXIT_SUCCESS0 : EXIT_FAILURE1);
76}