Bug Summary

File:build-scan/../src/test/test-strip-tab-ansi.c
Warning:line 55, column 16
Potential leak of memory pointed to by 'q'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test-strip-tab-ansi.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I test-strip-tab-ansi.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/test/test-strip-tab-ansi.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include <stdio.h>
4
5#include "alloc-util.h"
6#include "string-util.h"
7#include "terminal-util.h"
8#include "util.h"
9
10int main(int argc, char *argv[]) {
11 _cleanup_free___attribute__((cleanup(freep))) char *urlified = NULL((void*)0), *q = NULL((void*)0), *qq = NULL((void*)0);
12 char *p, *z;
13
14 assert_se(p = strdup("\tFoobar\tbar\twaldo\t"))do { if ((__builtin_expect(!!(!(p = strdup("\tFoobar\tbar\twaldo\t"
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("p = strdup(\"\\tFoobar\\tbar\\twaldo\\t\")"
), "../src/test/test-strip-tab-ansi.c", 14, __PRETTY_FUNCTION__
); } while (0)
;
1
Assuming 'p' is non-null
2
Taking false branch
3
Loop condition is false. Exiting loop
15 assert_se(strip_tab_ansi(&p, NULL, NULL))do { if ((__builtin_expect(!!(!(strip_tab_ansi(&p, ((void
*)0), ((void*)0)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("strip_tab_ansi(&p, NULL, NULL)"), "../src/test/test-strip-tab-ansi.c"
, 15, __PRETTY_FUNCTION__); } while (0)
;
4
Assuming the condition is false
5
Taking false branch
6
Loop condition is false. Exiting loop
16 fprintf(stdoutstdout, "<%s>\n", p);
17 assert_se(streq(p, " Foobar bar waldo "))do { if ((__builtin_expect(!!(!((strcmp((p),(" Foobar bar waldo "
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, \" Foobar bar waldo \")"
), "../src/test/test-strip-tab-ansi.c", 17, __PRETTY_FUNCTION__
); } while (0)
;
7
Taking false branch
8
Loop condition is false. Exiting loop
18 free(p);
19
20 assert_se(p = strdup(ANSI_HIGHLIGHT "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED " world!" ANSI_NORMAL))do { if ((__builtin_expect(!!(!(p = strdup("\x1B[0;1;39m" "Hello"
"\x1B[0m" "\x1B[0;1;31m" " world!" "\x1B[0m"))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("p = strdup(ANSI_HIGHLIGHT \"Hello\" ANSI_NORMAL ANSI_HIGHLIGHT_RED \" world!\" ANSI_NORMAL)"
), "../src/test/test-strip-tab-ansi.c", 20, __PRETTY_FUNCTION__
); } while (0)
;
9
Assuming 'p' is non-null
10
Taking false branch
11
Loop condition is false. Exiting loop
21 assert_se(strip_tab_ansi(&p, NULL, NULL))do { if ((__builtin_expect(!!(!(strip_tab_ansi(&p, ((void
*)0), ((void*)0)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("strip_tab_ansi(&p, NULL, NULL)"), "../src/test/test-strip-tab-ansi.c"
, 21, __PRETTY_FUNCTION__); } while (0)
;
12
Assuming the condition is false
13
Taking false branch
14
Loop condition is false. Exiting loop
22 fprintf(stdoutstdout, "<%s>\n", p);
23 assert_se(streq(p, "Hello world!"))do { if ((__builtin_expect(!!(!((strcmp((p),("Hello world!"))
== 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, \"Hello world!\")"
), "../src/test/test-strip-tab-ansi.c", 23, __PRETTY_FUNCTION__
); } while (0)
;
15
Taking false branch
16
Loop condition is false. Exiting loop
24 free(p);
25
26 assert_se(p = strdup("\x1B[\x1B[\t\x1B[" ANSI_HIGHLIGHT "\x1B[" "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED " world!" ANSI_NORMAL))do { if ((__builtin_expect(!!(!(p = strdup("\x1B[\x1B[\t\x1B["
"\x1B[0;1;39m" "\x1B[" "Hello" "\x1B[0m" "\x1B[0;1;31m" " world!"
"\x1B[0m"))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("p = strdup(\"\\x1B[\\x1B[\\t\\x1B[\" ANSI_HIGHLIGHT \"\\x1B[\" \"Hello\" ANSI_NORMAL ANSI_HIGHLIGHT_RED \" world!\" ANSI_NORMAL)"
), "../src/test/test-strip-tab-ansi.c", 26, __PRETTY_FUNCTION__
); } while (0)
;
17
Assuming 'p' is non-null
18
Taking false branch
19
Loop condition is false. Exiting loop
27 assert_se(strip_tab_ansi(&p, NULL, NULL))do { if ((__builtin_expect(!!(!(strip_tab_ansi(&p, ((void
*)0), ((void*)0)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("strip_tab_ansi(&p, NULL, NULL)"), "../src/test/test-strip-tab-ansi.c"
, 27, __PRETTY_FUNCTION__); } while (0)
;
20
Assuming the condition is false
21
Taking false branch
22
Loop condition is false. Exiting loop
28 assert_se(streq(p, "\x1B[\x1B[ \x1B[\x1B[Hello world!"))do { if ((__builtin_expect(!!(!((strcmp((p),("\x1B[\x1B[ \x1B[\x1B[Hello world!"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, \"\\x1B[\\x1B[ \\x1B[\\x1B[Hello world!\")"
), "../src/test/test-strip-tab-ansi.c", 28, __PRETTY_FUNCTION__
); } while (0)
;
23
Taking false branch
24
Loop condition is false. Exiting loop
29 free(p);
30
31 assert_se(p = strdup("\x1B[waldo"))do { if ((__builtin_expect(!!(!(p = strdup("\x1B[waldo"))),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("p = strdup(\"\\x1B[waldo\")"
), "../src/test/test-strip-tab-ansi.c", 31, __PRETTY_FUNCTION__
); } while (0)
;
25
Assuming 'p' is non-null
26
Taking false branch
27
Loop condition is false. Exiting loop
32 assert_se(strip_tab_ansi(&p, NULL, NULL))do { if ((__builtin_expect(!!(!(strip_tab_ansi(&p, ((void
*)0), ((void*)0)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("strip_tab_ansi(&p, NULL, NULL)"), "../src/test/test-strip-tab-ansi.c"
, 32, __PRETTY_FUNCTION__); } while (0)
;
28
Assuming the condition is false
29
Taking false branch
30
Loop condition is false. Exiting loop
33 assert_se(streq(p, "\x1B[waldo"))do { if ((__builtin_expect(!!(!((strcmp((p),("\x1B[waldo")) ==
0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, \"\\x1B[waldo\")"
), "../src/test/test-strip-tab-ansi.c", 33, __PRETTY_FUNCTION__
); } while (0)
;
31
Taking false branch
32
Loop condition is false. Exiting loop
34 free(p);
35
36 assert_se(terminal_urlify_path("/etc/fstab", "i am a fabulous link", &urlified) >= 0)do { if ((__builtin_expect(!!(!(terminal_urlify_path("/etc/fstab"
, "i am a fabulous link", &urlified) >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("terminal_urlify_path(\"/etc/fstab\", \"i am a fabulous link\", &urlified) >= 0"
), "../src/test/test-strip-tab-ansi.c", 36, __PRETTY_FUNCTION__
); } while (0)
;
33
Assuming the condition is true
34
Taking false branch
35
Loop condition is false. Exiting loop
37 assert_se(p = strjoin("something ", urlified, " something-else"))do { if ((__builtin_expect(!!(!(p = strjoin_real(("something "
), urlified, " something-else", ((void*)0)))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("p = strjoin(\"something \", urlified, \" something-else\")"
), "../src/test/test-strip-tab-ansi.c", 37, __PRETTY_FUNCTION__
); } while (0)
;
36
Assuming 'p' is non-null
37
Taking false branch
38
Loop condition is false. Exiting loop
38 assert_se(q = strdup(p))do { if ((__builtin_expect(!!(!(q = strdup(p))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("q = strdup(p)"), "../src/test/test-strip-tab-ansi.c"
, 38, __PRETTY_FUNCTION__); } while (0)
;
39
Memory is allocated
40
Assuming 'q' is non-null
41
Taking false branch
42
Loop condition is false. Exiting loop
39 printf("<%s>\n", p);
40 assert_se(strip_tab_ansi(&p, NULL, NULL))do { if ((__builtin_expect(!!(!(strip_tab_ansi(&p, ((void
*)0), ((void*)0)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("strip_tab_ansi(&p, NULL, NULL)"), "../src/test/test-strip-tab-ansi.c"
, 40, __PRETTY_FUNCTION__); } while (0)
;
43
Assuming the condition is false
44
Taking false branch
45
Loop condition is false. Exiting loop
41 printf("<%s>\n", p);
42 assert_se(streq(p, "something i am a fabulous link something-else"))do { if ((__builtin_expect(!!(!((strcmp((p),("something i am a fabulous link something-else"
)) == 0))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(p, \"something i am a fabulous link something-else\")"
), "../src/test/test-strip-tab-ansi.c", 42, __PRETTY_FUNCTION__
); } while (0)
;
46
Taking false branch
47
Loop condition is false. Exiting loop
43 p = mfree(p);
44
45 /* Truncate the formatted string in the middle of an ANSI sequence (in which case we shouldn't touch the
46 * incomplete sequence) */
47 z = strstr(q, "fstab");
48 if (z) {
48
Assuming 'z' is null
49
Taking false branch
49 *z = 0;
50 assert_se(qq = strdup(q))do { if ((__builtin_expect(!!(!(qq = strdup(q))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("qq = strdup(q)"), "../src/test/test-strip-tab-ansi.c"
, 50, __PRETTY_FUNCTION__); } while (0)
;
51 assert_se(strip_tab_ansi(&q, NULL, NULL))do { if ((__builtin_expect(!!(!(strip_tab_ansi(&q, ((void
*)0), ((void*)0)))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("strip_tab_ansi(&q, NULL, NULL)"), "../src/test/test-strip-tab-ansi.c"
, 51, __PRETTY_FUNCTION__); } while (0)
;
52 assert_se(streq(q, qq))do { if ((__builtin_expect(!!(!((strcmp((q),(qq)) == 0))),0))
) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("streq(q, qq)")
, "../src/test/test-strip-tab-ansi.c", 52, __PRETTY_FUNCTION__
); } while (0)
;
53 }
54
55 return 0;
50
Potential leak of memory pointed to by 'q'
56}