diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2012-08-03 21:56:41 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2012-08-03 21:56:41 -0400 |
commit | 3d89049546d98a33da41dc43d7b360dffe2c2fb0 (patch) | |
tree | 6666f044bc7331fc26739380419e97912f448cca /shared | |
parent | 248aaecda24ee4d2826d79a510176d2c634d8ac6 (diff) |
config-parser: Handle lines that don't end in \n
If the last line in a config file doesn't have a newline
we end up chopping off the last character from that line.
Diffstat (limited to 'shared')
-rw-r--r-- | shared/config-parser.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/shared/config-parser.c b/shared/config-parser.c index 5ffa4664..10ff86a9 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -24,6 +24,7 @@ #include <stdio.h> #include <stdlib.h> #include <assert.h> +#include <ctype.h> #include "config-parser.h" @@ -55,11 +56,13 @@ handle_key(const struct config_key *key, const char *value) case CONFIG_KEY_STRING: len = strlen(value); - s = malloc(len); + while (len > 0 && isspace(value[len - 1])) + len--; + s = malloc(len + 1); if (s == NULL) return -1; - memcpy(s, value, len - 1); - s[len - 1] = '\0'; + memcpy(s, value, len); + s[len] = '\0'; *(char **)key->data = s; return 0; |