diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2020-07-10 14:57:57 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2020-07-13 18:41:00 +1000 |
commit | 41a7c975f8e5d1f4e74fd945f6f1aecc9ef4b498 (patch) | |
tree | 6cd4eb98fe11bb0410edd0452175fbd93bfb19e9 /test | |
parent | 2cb90c958f7efa36b00fe845c38bbe0d00e15b1e (diff) | |
download | xorg-lib-libxkbcommon-41a7c975f8e5d1f4e74fd945f6f1aecc9ef4b498.tar.gz |
Add asprintf_safe helper function
We only ever care about whether we error out or not, so let's wrap this into
something more sane.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rw-r--r-- | test/common.c | 7 | ||||
-rw-r--r-- | test/compose.c | 10 | ||||
-rw-r--r-- | test/context.c | 4 | ||||
-rw-r--r-- | test/registry.c | 4 |
4 files changed, 11 insertions, 14 deletions
diff --git a/test/common.c b/test/common.c index d6619d4..c6f6644 100644 --- a/test/common.c +++ b/test/common.c @@ -165,7 +165,6 @@ test_key_seq(struct xkb_keymap *keymap, ...) char * test_get_path(const char *path_rel) { - int ret; char *path; const char *srcdir; @@ -176,9 +175,9 @@ test_get_path(const char *path_rel) if (path_rel[0] == '/') return strdup(path_rel); - ret = asprintf(&path, "%s/test/data%s%s", srcdir, - path_rel[0] ? "/" : "", path_rel); - if (ret < 0) { + path = asprintf_safe("%s/test/data%s%s", srcdir, + path_rel[0] ? "/" : "", path_rel); + if (!path) { fprintf(stderr, "Failed to allocate path for %s\n", path_rel); return NULL; } diff --git a/test/compose.c b/test/compose.c index 37d33bb..5ba5751 100644 --- a/test/compose.c +++ b/test/compose.c @@ -485,18 +485,16 @@ static void test_include(struct xkb_context *ctx) { char *path, *table_string; - int ret; path = test_get_path("compose/en_US.UTF-8/Compose"); assert(path); /* We don't have a mechanism to change the include paths like we * have for keymaps. So we must include the full path. */ - ret = asprintf(&table_string, - "<dead_tilde> <space> : \"foo\" X\n" - "include \"%s\"\n" - "<dead_tilde> <dead_tilde> : \"bar\" Y\n", path); - assert(ret >= 0); + table_string = asprintf_safe("<dead_tilde> <space> : \"foo\" X\n" + "include \"%s\"\n" + "<dead_tilde> <dead_tilde> : \"bar\" Y\n", path); + assert(table_string); assert(test_compose_seq_buffer(ctx, table_string, /* No conflict. */ diff --git a/test/context.c b/test/context.c index 2f5fd37..f91be54 100644 --- a/test/context.c +++ b/test/context.c @@ -85,8 +85,8 @@ static const char *makedir(const char *parent, const char *path) char *dirname; int err; - err = asprintf(&dirname, "%s/%s", parent, path); - assert(err >= 0); + dirname = asprintf_safe("%s/%s", parent, path); + assert(dirname); err = mkdir(dirname, 0777); assert(err == 0); diff --git a/test/registry.c b/test/registry.c index 68e74d0..fc5f6da 100644 --- a/test/registry.c +++ b/test/registry.c @@ -104,8 +104,8 @@ test_create_rules(const char *ruleset, int rc; FILE *fp; - rc = asprintf(&tmpdir, "/tmp/%s.%d.XXXXXX", ruleset, iteration++); - assert(rc > 0); + tmpdir = asprintf_safe("/tmp/%s.%d.XXXXXX", ruleset, iteration++); + assert(tmpdir); assert(mkdtemp(tmpdir) == tmpdir); rc = snprintf_safe(buf, sizeof(buf), "%s/rules", tmpdir); |