diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-19 09:46:15 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2023-05-04 18:46:16 +1000 |
commit | a50890b155e37d4347b1ec238ec998e6ad19476d (patch) | |
tree | 20f7f2c1d1cb125c48247412837cdf10a3b6dff4 | |
parent | 46b7753fb816901c17266f59306e85029307bc16 (diff) | |
download | libxkbcommon-a50890b155e37d4347b1ec238ec998e6ad19476d.tar.gz libxkbcommon-a50890b155e37d4347b1ec238ec998e6ad19476d.tar.bz2 libxkbcommon-a50890b155e37d4347b1ec238ec998e6ad19476d.zip |
registry: simplify strdup() error handling
strdup() is the least likely call to fail here, let's move it to the bottom so
we don't need to worry about the allocated string.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/registry.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/registry.c b/src/registry.c index 0c42a3b..e23e87b 100644 --- a/src/registry.c +++ b/src/registry.c @@ -564,18 +564,14 @@ rxkb_context_include_path_append(struct rxkb_context *ctx, const char *path) return false; } - tmp = strdup(path); - if (!tmp) - goto err; - err = stat(path, &stat_buf); if (err != 0) - goto err; + return false; if (!S_ISDIR(stat_buf.st_mode)) - goto err; + return false; if (!check_eaccess(path, R_OK | X_OK)) - goto err; + return false; /* Pre-filter for the 99.9% case - if we can't assemble the default ruleset * path, complain here instead of during parsing later. The niche cases @@ -583,15 +579,15 @@ rxkb_context_include_path_append(struct rxkb_context *ctx, const char *path) */ if (!snprintf_safe(rules, sizeof(rules), "%s/rules/%s.xml", path, DEFAULT_XKB_RULES)) - goto err; + return false; + + tmp = strdup(path); + if (!tmp) + return false; darray_append(ctx->includes, tmp); return true; - -err: - free(tmp); - return false; } XKB_EXPORT bool |