diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-26 02:15:59 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-26 02:15:59 -0400 |
commit | 37ec63ece45c7f27f576e1fb5911b55630125d03 (patch) | |
tree | 843d82c165c784997bedf2ad36f078f932b1643d /lib/config.c | |
parent | d0925dcc2e34d6f9a8c554ca97c4d75784e6f69d (diff) | |
download | spmc-37ec63ece45c7f27f576e1fb5911b55630125d03.tar.gz |
Fix segfault caused by freeing records for no reason:
* split() returns the input string when no delimiters are found
Diffstat (limited to 'lib/config.c')
-rw-r--r-- | lib/config.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/config.c b/lib/config.c index 88c96fd..292c633 100644 --- a/lib/config.c +++ b/lib/config.c @@ -22,7 +22,8 @@ * @return success=`ConfigItem` array, failure=NULL */ ConfigItem **config_read(const char *filename) { - const char sep = '='; + const char sep_ch = '='; + const char sep_str[] = {sep_ch, '\0'}; size_t record = 0; char *line = NULL; FILE *fp = NULL; @@ -71,16 +72,16 @@ ConfigItem **config_read(const char *filename) { } // Get a pointer to the key pair separator - char *sep_pos = strchr(lptr, sep); + char *sep_pos = strchr(lptr, sep_ch); if (!sep_pos) { - printf("invalid entry on line %zu: missing '%c': '%s'\n", record, sep, lptr); + printf("invalid entry on line %zu: missing '%s': '%s'\n", record, sep_str, lptr); continue; } // These values are approximations. The real length(s) are recorded using strlen below. // At most we'll lose a few heap bytes to whitespace, but it's better than allocating PATH_MAX or BUFSIZ // for a measly ten byte string. - size_t key_length = strcspn(lptr, &sep); + size_t key_length = strcspn(lptr, sep_str); size_t value_length = strlen(sep_pos); // Allocate a ConfigItem record |