Bug Summary

File:.build-ci/../shared/test/test-wrap-util.c
Warning:line 26, 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-wrap-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-wrap-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-wrap-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 <wrap-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(const char *s, int indent, int start)
19{
20 static char buf[1024];
21 FILE *stream = tmpfile();
22 size_t n;
23
24 shr_print_word_wrapped(s, indent, start, stream);
25 rewind(stream);
2
After calling 'rewind' reading 'errno' is required to find out if the call has failed
26 n = fread(buf, 1, sizeof(buf) - 1, stream);
3
Value of 'errno' was not checked and may be overwritten by function 'fread'
27 buf[n] = '\0';
28 fclose(stream);
29
30 return buf;
31}
32
33int main(void)
34{
35 bool_Bool pass = true1;
36 char *out;
37
38 printf("test_print_word_wrapped:\n");
39
40 out = capture("short text", 0, 0);
1
Calling 'capture'
41 pass &= check_bool("short text fits on one line", strchr(out, '\n')_Generic (0 ? (out) : (void *) 1, const void *: (const char *
) (strchr (out, '\n')), default: strchr (out, '\n'))
== NULL((void*)0));
42 pass &= check_bool("short text is printed verbatim", !strcmp(out, "short text"));
43
44 out = capture("one two three four five six seven eight nine ten eleven twelve "
45 "thirteen fourteen fifteen sixteen", 4, 4);
46 pass &= check_bool("long text wraps onto more than one line", strchr(out, '\n')_Generic (0 ? (out) : (void *) 1, const void *: (const char *
) (strchr (out, '\n')), default: strchr (out, '\n'))
!= NULL((void*)0));
47 pass &= check_bool("wrapped continuation line is indented",
48 strstr(out, "\n ")_Generic (0 ? (out) : (void *) 1, const void *: (const char *
) (strstr (out, "\n ")), default: strstr (out, "\n "))
!= NULL((void*)0));
49
50 out = capture("line one\nline two", 2, 0);
51 pass &= check_bool("embedded newline forces a break",
52 strstr(out, "line one\n line two")_Generic (0 ? (out) : (void *) 1, const void *: (const char *
) (strstr (out, "line one\n line two")), default: strstr (out
, "line one\n line two"))
!= NULL((void*)0));
53
54 fflush(stdoutstdout);
55 exit(pass ? EXIT_SUCCESS0 : EXIT_FAILURE1);
56}