diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2020-07-17 01:09:47 +0200 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2020-07-23 09:39:53 +0300 |
commit | ddd1188d971283e6cbcd7bcf8cbc056a75b91ced (patch) | |
tree | 833ba3f8d9ec8218ff163e95913d6c6b37ab350e /src | |
parent | 17ad0df14ad3414de3d69e75f448a1f4acb637c3 (diff) | |
download | xorg-lib-libxkbcommon-ddd1188d971283e6cbcd7bcf8cbc056a75b91ced.tar.gz |
Make path retrieval consistent in xkb_compose_table_new_from_locale()
Diffstat (limited to 'src')
-rw-r--r-- | src/compose/paths.c | 4 | ||||
-rw-r--r-- | src/compose/paths.h | 2 | ||||
-rw-r--r-- | src/compose/table.c | 22 |
3 files changed, 13 insertions, 15 deletions
diff --git a/src/compose/paths.c b/src/compose/paths.c index aab4507..dab71ac 100644 --- a/src/compose/paths.c +++ b/src/compose/paths.c @@ -143,10 +143,10 @@ resolve_locale(const char *locale) return alias ? alias : strdup(locale); } -const char * +char * get_xcomposefile_path(void) { - return secure_getenv("XCOMPOSEFILE"); + return strdup_safe(secure_getenv("XCOMPOSEFILE")); } char * diff --git a/src/compose/paths.h b/src/compose/paths.h index 53d7415..bc5150f 100644 --- a/src/compose/paths.h +++ b/src/compose/paths.h @@ -30,7 +30,7 @@ resolve_locale(const char *locale); const char * get_xlocaledir_path(void); -const char * +char * get_xcomposefile_path(void); char * diff --git a/src/compose/table.c b/src/compose/table.c index 1843c46..38d4406 100644 --- a/src/compose/table.c +++ b/src/compose/table.c @@ -161,8 +161,7 @@ xkb_compose_table_new_from_locale(struct xkb_context *ctx, enum xkb_compose_compile_flags flags) { struct xkb_compose_table *table; - char *path = NULL; - const char *cpath; + char *path; FILE *file; bool ok; @@ -176,48 +175,47 @@ xkb_compose_table_new_from_locale(struct xkb_context *ctx, if (!table) return NULL; - cpath = get_xcomposefile_path(); - if (cpath) { - file = fopen(cpath, "rb"); + path = get_xcomposefile_path(); + if (path) { + file = fopen(path, "rb"); if (file) goto found_path; } + free(path); - cpath = path = get_xdg_xcompose_file_path(); + path = get_xdg_xcompose_file_path(); if (path) { file = fopen(path, "rb"); if (file) goto found_path; } free(path); - path = NULL; - cpath = path = get_home_xcompose_file_path(); + path = get_home_xcompose_file_path(); if (path) { file = fopen(path, "rb"); if (file) goto found_path; } free(path); - path = NULL; - cpath = path = get_locale_compose_file_path(table->locale); + path = get_locale_compose_file_path(table->locale); if (path) { file = fopen(path, "rb"); if (file) goto found_path; } free(path); - path = NULL; log_err(ctx, "couldn't find a Compose file for locale \"%s\"\n", locale); xkb_compose_table_unref(table); return NULL; found_path: - ok = parse_file(table, file, cpath); + ok = parse_file(table, file, path); fclose(file); if (!ok) { + free(path); xkb_compose_table_unref(table); return NULL; } |