File: | build-scan/../src/test/test-strip-tab-ansi.c |
Warning: | line 55, column 16 Potential leak of memory pointed to by 'q' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | ||||
10 | int 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); | |||
| ||||
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); | |||
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); | |||
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); | |||
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); | |||
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); | |||
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); | |||
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); | |||
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); | |||
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); | |||
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); | |||
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); | |||
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); | |||
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); | |||
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 | 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); | |||
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); | |||
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) { | |||
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; | |||
| ||||
56 | } |