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 utils.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 pic -pic-level 2 -pic-is-pie -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/lib/llvm-19/lib/clang/19 -include /__w/nvme-cli/nvme-cli/.build-ci/nvme-config.h -I libnvme/test/test-mi.p -I libnvme/test -I ../libnvme/test -I . -I .. -I ccan -I ../ccan -I libnvme/src -I ../libnvme/src -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -U NDEBUG -internal-isystem /usr/lib/llvm-19/lib/clang/19/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 -O3 -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 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /__w/nvme-cli/nvme-cli/.build-ci/scan-results/2026-06-24-175442-590-1 -x c ../libnvme/test/utils.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | #include <err.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <unistd.h> |
| 13 | |
| 14 | #include "utils.h" |
| 15 | |
| 16 | FILE *test_setup_log(void) |
| 17 | { |
| 18 | FILE *fd; |
| 19 | |
| 20 | fd = tmpfile(); |
| 21 | if (!fd) |
| 22 | err(EXIT_FAILURE, "can't create temporary file for log buf"); |
| 23 | |
| 24 | return fd; |
| 25 | } |
| 26 | |
| 27 | void test_close_log(FILE *fd) |
| 28 | { |
| 29 | fclose(fd); |
| 30 | } |
| 31 | |
| 32 | void test_print_log_buf(FILE *logfd) |
| 33 | { |
| 34 | char buf[4096]; |
| 35 | int rc; |
| 36 | |
| 37 | if (!ftell(logfd)) |
| |
| 38 | return; |
| 39 | |
| 40 | rewind(logfd); |
| 41 | |
| 42 | printf("--- begin test output\n"); |
| 43 | |
| 44 | while (!feof(logfd) && !ferror(logfd)) { |
| 2 | | Assuming the condition is false | |
|
| 45 | size_t rlen, wlen, wpos; |
| 46 | |
| 47 | rlen = fread(buf, 1, sizeof(buf), logfd); |
| 48 | if (rlen <= 0) |
| 49 | break; |
| 50 | |
| 51 | for (wpos = 0; wpos < rlen;) { |
| 52 | wlen = fwrite(buf + wpos, 1, rlen - wpos, stdout); |
| 53 | if (wlen == 0) |
| 54 | break; |
| 55 | wpos += wlen; |
| 56 | } |
| 57 | |
| 58 | if (feof(logfd) || ferror((logfd))) |
| 59 | break; |
| 60 | } |
| 61 | |
| 62 | printf("--- end test output\n"); |
| 63 | rewind(logfd); |
| 3 | | After calling 'rewind' reading 'errno' is required to find out if the call has failed | |
|
| 64 | rc = ftruncate(fileno(logfd), 0); |
| 4 | | Value of 'errno' was not checked and may be overwritten by function 'fileno' |
|
| 65 | if (rc) |
| 66 | printf("failed to truncate log buf; further output may be invalid\n"); |
| 67 | } |
| 68 | |