summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-08-06 12:16:33 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-08-06 12:16:33 -0300
commit32329a4084df0a12ff0e4b3853859c778a902468 (patch)
tree861fa01a6c8c2056173a13f96ef4ff7af7474026
parentfbe98f57dc779069bd283ac1773866ce73727ea0 (diff)
keyword: Check validity of keyword value in `create_key_value_file()`
This needs to be done, in case we get a string that's `NULL`.
-rw-r--r--keyword.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/keyword.c b/keyword.c
index c20f560..385f526 100644
--- a/keyword.c
+++ b/keyword.c
@@ -234,7 +234,8 @@ char *create_key_value_file(void *data, void *ctx, const keyword **keywords, con
for (int i = 0; keywords[i] != NULL; ++i) {
int error;
keyword_val val = get_keyword(keywords[i], data, ctx, &error);
- if (!error || error < 0) {
+ const int is_valid = keywords[i]->type != TYPE_STRING || (keywords[i]->type == TYPE_STRING && !is_empty(val.str));
+ if ((!error || error < 0) && is_valid) {
char *key_value = create_key_value_str(keywords[i], val, start_delm, end_delm);
buf_len += strlen(key_value);
key_values = add_node(&key_values, key_value);