Skip to contentSkip to conversation

parse_keyval: Allow hex vals

PATCH In review Andrew Jones 4 participants 4 messages Oct 8, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 parse_keyval: Allow hex vals

When parse_keyval was first written we didn't yet have strtol. Now we do, let's give users more flexibility.

---
 lib/util.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/util.c +2 -1
index a90554138952..682ca2db09e6 100644
@@ -4,6 +4,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #include <libcflat.h>
+#include <stdlib.h>
 #include "util.h"
 
 int parse_keyval(char *s, long *val)
@@ -14,6 +15,6 @@ int parse_keyval(char *s, long *val)
 	if (!p)
 		return -1;
 
-	*val = atol(p+1);
+	*val = strtol(p+1, NULL, 0);
 	return p - s;
 }
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Andrew Jones

When parse_keyval was first written we didn't yet have strtol. Now we do, let's give users more flexibility.

---
  lib/util.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
lib/util.c +1 -0
index a90554138952..682ca2db09e6 100644
@@ -4,6 +4,7 @@
   * This work is licensed under the terms of the GNU LGPL, version 2.
   */
  #include <libcflat.h>
+#include <stdlib.h>
  #include "util.h"
 
  int parse_keyval(char *s, long *val)

lib/util.c int parse_keyval(char *s, long *val) · line 20

Quoted 7 lines
lib/util.c +1 -1
@@ -14,6 +15,6 @@ int parse_keyval(char *s, long *val)
  	if (!p)
  		return -1;
 
-	*val = atol(p+1);
+	*val = strtol(p+1, NULL, 0);
  	return p - s;
  }
Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrew Jones
Quoted 31 lines · Andrew Jones

When parse_keyval was first written we didn't yet have strtol. Now we do, let's give users more flexibility.

---
 lib/util.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/util.c +2 -1
index a90554138952..682ca2db09e6 100644
@@ -4,6 +4,7 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #include <libcflat.h>
+#include <stdlib.h>
 #include "util.h"
 
 int parse_keyval(char *s, long *val)
@@ -14,6 +15,6 @@ int parse_keyval(char *s, long *val)
 	if (!p)
 		return -1;
 
-	*val = atol(p+1);
+	*val = strtol(p+1, NULL, 0);
 	return p - s;
 }
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#3 lore raw
In reply to Andrew Jones
Quoted 22 lines · Andrew Jones

When parse_keyval was first written we didn't yet have strtol. Now we do, let's give users more flexibility.

---
  lib/util.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
lib/util.c +1 -0
index a90554138952..682ca2db09e6 100644
@@ -4,6 +4,7 @@
   * This work is licensed under the terms of the GNU LGPL, version 2.
   */
  #include <libcflat.h>
+#include <stdlib.h>
  #include "util.h"
 
  int parse_keyval(char *s, long *val)

lib/util.c int parse_keyval(char *s, long *val) · line 20

Quoted 7 lines
lib/util.c +1 -1
@@ -14,6 +15,6 @@ int parse_keyval(char *s, long *val)
  	if (!p)
  		return -1;
 
-	*val = atol(p+1);
+	*val = strtol(p+1, NULL, 0);
  	return p - s;
  }