aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-08-07 11:06:47 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-08-07 11:06:47 -0400
commit3560c2e01563f39bf3775f6afe1e12997fe99969 (patch)
tree87c85b345d997b02ac237d701e6622ebf0bfb884 /src
parent09906cbbad8a1fe1ad442110dbeabff63540d656 (diff)
downloadstasis-3560c2e01563f39bf3775f6afe1e12997fe99969.tar.gz
ini_getval: Return copies, not the original.
* This forces one to use ini_setval to replace/append values to the data array(s). It's safer this way.
Diffstat (limited to 'src')
-rw-r--r--src/ini.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/ini.c b/src/ini.c
index 37d80fe..bddfdcd 100644
--- a/src/ini.c
+++ b/src/ini.c
@@ -168,17 +168,26 @@ int ini_getval(struct INIFILE *ini, char *section_name, char *key, int type, uni
result->as_float = (float) strtod(data->value, NULL);
break;
case INIVAL_TYPE_STR:
- result->as_char_p = lstrip(data->value);
+ result->as_char_p = strdup(data->value);
+ if (!result->as_char_p) {
+ return -1;
+ }
+ lstrip(result->as_char_p);
break;
case INIVAL_TYPE_STR_ARRAY:
strcpy(tbufp, data->value);
- *data->value = '\0';
+ char *value = NULL;
+ size_t lines = num_chars(tbufp, '\n');
+ value = calloc(strlen(tbufp) + lines + 1, sizeof(*value));
+ if (!value) {
+ return -1;
+ }
while ((token = strsep(&tbufp, "\n")) != NULL) {
lstrip(token);
- strcat(data->value, token);
- strcat(data->value, "\n");
+ strcat(value, token);
+ strcat(value, "\n");
}
- result->as_char_p = data->value;
+ result->as_char_p = value;
break;
case INIVAL_TYPE_BOOL:
result->as_bool = false;