Skip to contentSkip to conversation

settings: Parse non-base-10 integer settings

PATCH Applied Andrew Zaborowski 2 participants 2 messages Mar 25, 2020 – Mar 26, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 settings: Parse non-base-10 integer settings

Change the stro{,u}{l,ll} base parameter to 0 to not disallow hex or octal numbers, useful for bitmasks.

---
 ell/settings.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ell/settings.c +4 -4
index c5e1184..f4326d6 100644
@@ -998,7 +998,7 @@ LIB_EXPORT bool l_settings_get_int(const struct l_settings *settings,
 
 	errno = 0;
 
-	t = r = strtol(value, &endp, 10);
+	t = r = strtol(value, &endp, 0);
 	if (*endp != '\0')
 		goto error;
 
@@ -1045,7 +1045,7 @@ LIB_EXPORT bool l_settings_get_uint(const struct l_settings *settings,
 
 	errno = 0;
 
-	t = r = strtoul(value, &endp, 10);
+	t = r = strtoul(value, &endp, 0);
 	if (*endp != '\0')
 		goto error;
 
@@ -1091,7 +1091,7 @@ LIB_EXPORT bool l_settings_get_int64(const struct l_settings *settings,
 
 	errno = 0;
 
-	r = strtoll(value, &endp, 10);
+	r = strtoll(value, &endp, 0);
 	if (*endp != '\0')
 		goto error;
 
@@ -1137,7 +1137,7 @@ LIB_EXPORT bool l_settings_get_uint64(const struct l_settings *settings,
 
 	errno = 0;
 
-	r = strtoull(value, &endp, 10);
+	r = strtoull(value, &endp, 0);
 	if (*endp != '\0')
 		goto error;
 
Signature · 1 line
2.20.1
#1 lore raw

hi Andrew,

Quoted 5 lines · Andrew Zaborowski

Change the stro{,u}{l,ll} base parameter to 0 to not disallow hex or octal numbers, useful for bitmasks.

---
  ell/settings.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

Applied, thanks.

Regards,
-Denis