summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2020-07-10 15:01:31 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2020-07-13 18:41:00 +1000
commitd4b78a5fca47c27aac4cea0220ad595c3312807f (patch)
treea0f2823c75d781dec159d55b4d587a69cb492974 /src
parent41a7c975f8e5d1f4e74fd945f6f1aecc9ef4b498 (diff)
downloadxorg-lib-libxkbcommon-d4b78a5fca47c27aac4cea0220ad595c3312807f.tar.gz
xkbcomp: simplify buffer handling in the include handling
Don't do the realloc dance, just asprintf to the buffer and move on. The check is likely pointless anyway, if we run out of asprintf size, log_error will probably blow up as well. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r--src/xkbcomp/include.c32
1 files changed, 9 insertions, 23 deletions
diff --git a/src/xkbcomp/include.c b/src/xkbcomp/include.c
index 8b97558..556b438 100644
--- a/src/xkbcomp/include.c
+++ b/src/xkbcomp/include.c
@@ -203,39 +203,25 @@ FindFileInXkbPath(struct xkb_context *ctx, const char *name,
FILE *file = NULL;
char *buf = NULL;
const char *typeDir;
- size_t buf_size = 0, typeDirLen, name_len;
typeDir = DirectoryForInclude(type);
- typeDirLen = strlen(typeDir);
- name_len = strlen(name);
for (i = 0; i < xkb_context_num_include_paths(ctx); i++) {
- size_t new_buf_size = strlen(xkb_context_include_path_get(ctx, i)) +
- typeDirLen + name_len + 3;
- int ret;
- if (new_buf_size > buf_size) {
- void *buf_new = realloc(buf, new_buf_size);
- if (buf_new) {
- buf_size = new_buf_size;
- buf = buf_new;
- } else {
- log_err(ctx, "Cannot realloc for name (%s/%s/%s)\n",
- xkb_context_include_path_get(ctx, i), typeDir, name);
- continue;
- }
- }
- ret = snprintf(buf, buf_size, "%s/%s/%s",
- xkb_context_include_path_get(ctx, i),
- typeDir, name);
- if (ret < 0) {
- log_err(ctx, "snprintf error (%s/%s/%s)\n",
+ buf = asprintf_safe("%s/%s/%s", xkb_context_include_path_get(ctx, i),
+ typeDir, name);
+ if (!buf) {
+ log_err(ctx, "Failed to alloc buffer for (%s/%s/%s)\n",
xkb_context_include_path_get(ctx, i), typeDir, name);
continue;
}
file = fopen(buf, "rb");
- if (file)
+ if (!file) {
+ free(buf);
+ buf = NULL;
+ } else {
break;
+ }
}
if (!file) {