diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-03-02 11:47:47 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-03-02 11:47:47 -0800 |
commit | c268499c305317d2e9a67cc590c9147e11438fc7 (patch) | |
tree | ad1ec3e56bf954ffde8be73b0334bfbab1b2406d /tests/check_public.c | |
parent | c671b9b30aecada4e43cb48e0dee46d19fb5cb9c (diff) |
tests: fix -Werror=discarded-qualifiers errors in check_public.c
check_public.c: In function ‘parse_display_pass’:
check_public.c:32:32: error: passing argument 1 of ‘putenv’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
32 | putenv("DISPLAY=");
| ^~~~~~~~~~
In file included from check_public.c:4:
/usr/include/stdlib.h:148:19: note: expected ‘char *’ but argument is of type ‘const char *’
148 | extern int putenv(char *);
| ^~~~~~
check_public.c:57:16: error: passing argument 1 of ‘putenv’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
57 | putenv("DISPLAY=");
| ^~~~~~~~~~
/usr/include/stdlib.h:148:19: note: expected ‘char *’ but argument is of type ‘const char *’
148 | extern int putenv(char *);
| ^~~~~~
check_public.c: In function ‘parse_display_fail’:
check_public.c:73:32: error: passing argument 1 of ‘putenv’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
73 | putenv("DISPLAY=");
| ^~~~~~~~~~
/usr/include/stdlib.h:148:19: note: expected ‘char *’ but argument is of type ‘const char *’
148 | extern int putenv(char *);
| ^~~~~~
check_public.c:99:16: error: passing argument 1 of ‘putenv’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
99 | putenv("DISPLAY=");
| ^~~~~~~~~~
/usr/include/stdlib.h:148:19: note: expected ‘char *’ but argument is of type ‘const char *’
148 | extern int putenv(char *);
| ^~~~~~
check_public.c: In function ‘public_suite’:
check_public.c:244:16: error: passing argument 1 of ‘putenv’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
244 | putenv("DISPLAY=");
| ^~~~~~~~~~
/usr/include/stdlib.h:148:19: note: expected ‘char *’ but argument is of type ‘const char *’
148 | extern int putenv(char *);
| ^~~~~~
cc1: all warnings being treated as errors
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'tests/check_public.c')
-rw-r--r-- | tests/check_public.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/tests/check_public.c b/tests/check_public.c index 3caac1e..e0b374b 100644 --- a/tests/check_public.c +++ b/tests/check_public.c @@ -16,6 +16,10 @@ typedef enum test_type_t { } test_type_t; static const char *const test_string[] = { "", "via $DISPLAY " }; +/* putenv(3) takes a pointer to a writable string that it adds directly + to the environment, so it must be in persistent memory, not on the stack */ +static char display_env[] = "DISPLAY="; + static void parse_display_pass(const char *name, const char *host, const int display, const int screen) { int success; @@ -29,7 +33,7 @@ static void parse_display_pass(const char *name, const char *host, const int dis if(test_type == TEST_ARGUMENT) { argument = name; - putenv("DISPLAY="); + putenv(display_env); } else if(test_type == TEST_ENVIRONMENT) { @@ -54,7 +58,7 @@ static void parse_display_pass(const char *name, const char *host, const int dis ck_assert_msg(strcmp(host, got_host) == 0, "screenless parse %sproduced unexpected hostname '%s' for '%s': expected '%s'", test_string[test_type], got_host, name, host); ck_assert_msg(display == got_display, "screenless parse %sproduced unexpected display '%d' for '%s': expected '%d'", test_string[test_type], got_display, name, display); } - putenv("DISPLAY="); + putenv(display_env); } static void parse_display_fail(const char *name) @@ -70,7 +74,7 @@ static void parse_display_fail(const char *name) if(test_type == TEST_ARGUMENT) { argument = name; - putenv("DISPLAY="); + putenv(display_env); } else if(test_type == TEST_ENVIRONMENT) { @@ -96,7 +100,7 @@ static void parse_display_fail(const char *name) ck_assert_msg(got_host == (char *) -1, "host changed on parse failure %sfor '%s': got %p", test_string[test_type], name, got_host); ck_assert_msg(got_display == -42, "display changed on parse failure %sfor '%s': got %d", test_string[test_type], name, got_display); } - putenv("DISPLAY="); + putenv(display_env); } START_TEST(parse_display_unix) @@ -241,7 +245,7 @@ END_TEST Suite *public_suite(void) { Suite *s = suite_create("Public API"); - putenv("DISPLAY="); + putenv(display_env); suite_add_test(s, parse_display_unix, "xcb_parse_display unix"); suite_add_test(s, parse_display_ip, "xcb_parse_display ip"); suite_add_test(s, parse_display_ipv4, "xcb_parse_display ipv4"); |