From 52f07a289e2ba14b908b01b09dfbb2e28e2def83 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Wed, 17 Apr 2024 11:08:19 +0600 Subject: [PATCH] Minor fixes --- source/libublsettings.c | 45 +++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/source/libublsettings.c b/source/libublsettings.c index e26785f..42dcdc2 100644 --- a/source/libublsettings.c +++ b/source/libublsettings.c @@ -1344,6 +1344,7 @@ void *yon_config_get_all_by_key(char *key, int *size){ } return ret_data; } + return NULL; } void *yon_config_get_all_by_key_no_ignored(char *key, int *size){ @@ -1500,33 +1501,47 @@ config_str yon_config_load(char *command, int *str_len){ } } -config_str yon_config_load_file(FILE *file, int *str_len){ +config_str yon_config_load_file(FILE *file, int *str_len) { FILE *output = file; char **output_strings = NULL; - output_strings = malloc(sizeof(char)); int i = 0; char str[4096]; - memset(str, 0, 4096); - while (fgets(str, 4096, output)) - { - if (strcmp(str, "") != 0) - { - output_strings = realloc(output_strings, sizeof(char *) * (i + 1)); - output_strings[i] = NULL; + + output_strings = malloc(sizeof(char *)); + if (!output_strings) { + *str_len = -1; + return NULL; + } + + while (fgets(str, sizeof(str), output)) { + if (strcmp(str, "") != 0) { output_strings[i] = yon_char_new(str); - memset(str, 0, 4096); + if (!output_strings[i]) { + *str_len = -1; + for (int j = 0; j < i; j++) { + free(output_strings[j]); + } + free(output_strings); + return NULL; + } i++; + output_strings = realloc(output_strings, sizeof(char *) * (i + 1)); + if (!output_strings) { + *str_len = -1; + for (int j = 0; j < i; j++) { + free(output_strings[j]); + } + free(output_strings); + return NULL; + } } } - if (i>0){ + *str_len = i; return output_strings; - } else{ - *str_len=-1; - return NULL; - } } + char *yon_config_parameter_to_string(yon_config_parameter *parameter, int insert_section){ if (parameter){ char *param_string = NULL;