From fe15496378bf664cc4ced3d5654523de9a5059fa Mon Sep 17 00:00:00 2001 From: swym <0xfd000000@gmail.com> Date: Tue, 27 Aug 2019 20:37:11 +0200 Subject: [PATCH] card10.cfg: have strtol detect base, fix zero-termination bug for strings --- epicardium/modules/config.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/epicardium/modules/config.c b/epicardium/modules/config.c index b1428dc3..5be76cd9 100644 --- a/epicardium/modules/config.c +++ b/epicardium/modules/config.c @@ -73,15 +73,7 @@ static bool set_int(struct config_option *opt, const char *value) { char *endptr; size_t len = strlen(value); - int base = 10; - if (len > 2 && value[0] == '0' && value[1] == 'x') { - base = 16; -#ifdef CONFIG_ENABLE_OCTAL_NUMBERS - } else if (len > 1 && value[0] == '0') { - base = 8; -#endif - } - int v = strtol(value, &endptr, base); + int v = strtol(value, &endptr, 0); if (endptr != (value + len)) { return false; } @@ -122,8 +114,9 @@ static bool set_string(struct config_option *opt, const char *value) { //this leaks, but the lifetime of these ends when epicardium exits, so... size_t len = strlen(value); - char *leaks = (char *)malloc(len); + char *leaks = (char *)malloc(len + 1); strncpy(leaks, value, len); + leaks[len] = '\0'; opt->value.string = leaks; LOG_DEBUG("card10.cfg", "setting '%s' to %s", opt->name, elide(leaks)); return true; -- GitLab