Skip to content
Snippets Groups Projects
Commit fe154963 authored by swym's avatar swym
Browse files

card10.cfg: have strtol detect base, fix zero-termination bug for

strings
parent 58d60e81
No related branches found
No related tags found
1 merge request!215feat(epicardium): read card10.cfg
...@@ -73,15 +73,7 @@ static bool set_int(struct config_option *opt, const char *value) ...@@ -73,15 +73,7 @@ static bool set_int(struct config_option *opt, const char *value)
{ {
char *endptr; char *endptr;
size_t len = strlen(value); size_t len = strlen(value);
int base = 10; int v = strtol(value, &endptr, 0);
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);
if (endptr != (value + len)) { if (endptr != (value + len)) {
return false; return false;
} }
...@@ -122,8 +114,9 @@ static bool set_string(struct config_option *opt, const char *value) ...@@ -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... //this leaks, but the lifetime of these ends when epicardium exits, so...
size_t len = strlen(value); size_t len = strlen(value);
char *leaks = (char *)malloc(len); char *leaks = (char *)malloc(len + 1);
strncpy(leaks, value, len); strncpy(leaks, value, len);
leaks[len] = '\0';
opt->value.string = leaks; opt->value.string = leaks;
LOG_DEBUG("card10.cfg", "setting '%s' to %s", opt->name, elide(leaks)); LOG_DEBUG("card10.cfg", "setting '%s' to %s", opt->name, elide(leaks));
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment