summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-07-13 23:31:32 -0400
committerDavid Robillard <d@drobilla.net>2022-07-17 17:57:14 -0400
commitf5bf578c16982400f91822d64782a328cea2c760 (patch)
tree738274b1fa82f86f89d70736a0b989986fec5905 /test
parent90e27de1acc7d52615c1f3a8599ff20a8fbfafb3 (diff)
downloadlilv-f5bf578c16982400f91822d64782a328cea2c760.tar.gz
lilv-f5bf578c16982400f91822d64782a328cea2c760.tar.bz2
lilv-f5bf578c16982400f91822d64782a328cea2c760.zip
Fix unlikely null dereference in test
Diffstat (limited to 'test')
-rw-r--r--test/test_string.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/test/test_string.c b/test/test_string.c
index 2d610bb..dcfd894 100644
--- a/test/test_string.c
+++ b/test/test_string.c
@@ -36,19 +36,27 @@ main(void)
#ifndef _WIN32
char* s = NULL;
+ const char* const home = getenv("HOME");
+
setenv("LILV_TEST_1", "test", 1);
- char* home_foo = lilv_strjoin(getenv("HOME"), "/foo", NULL);
+
assert(!strcmp((s = lilv_expand("$LILV_TEST_1")), "test"));
free(s);
- assert(!strcmp((s = lilv_expand("~")), getenv("HOME")));
- free(s);
- assert(!strcmp((s = lilv_expand("~foo")), "~foo"));
- free(s);
- assert(!strcmp((s = lilv_expand("~/foo")), home_foo));
- free(s);
+ if (home) {
+ assert(!strcmp((s = lilv_expand("~")), home));
+ free(s);
+ assert(!strcmp((s = lilv_expand("~foo")), "~foo"));
+ free(s);
+
+ char* const home_foo = lilv_strjoin(home, "/foo", NULL);
+ assert(!strcmp((s = lilv_expand("~/foo")), home_foo));
+ free(s);
+ free(home_foo);
+ }
+
assert(!strcmp((s = lilv_expand("$NOT_A_VAR")), "$NOT_A_VAR"));
free(s);
- free(home_foo);
+
unsetenv("LILV_TEST_1");
#endif