Skip to contentSkip to conversation

Introduce strtoll/strtoull

PATCH Applied Andrew Jones 3 participants 6 messages Oct 13, 2021 – Oct 15, 2021

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

cover Introduce strtoll/strtoull

A recent posting by Daniele Ahmed inspired me to write a patch adding strtoll/strtoull. While doing that I noticed check_mul_overflow wasn't working and found copy+paste errors with it and check_sub_overflow.

Andrew Jones (2):
compiler.h: Fix typos in mul and sub overflow checks
lib: Introduce strtoll/strtoull

 lib/linux/compiler.h |  4 ++--
 lib/stdlib.h         |  2 ++
 lib/string.c         | 51 ++++++++++++++++++++++++++++++++------------
 3 files changed, 41 insertions(+), 16 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 compiler.h: Fix typos in mul and sub overflow checks

Fixes 4ceb02bf68f0 ("compiler: Add builtin overflow flag and predicate wrappers")
---
 lib/linux/compiler.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/linux/compiler.h +2 -2
index c7fc0cf0852e..6f565e4a5107 100644
@@ -33,8 +33,8 @@
 #elif GCC_VERSION >= 70100
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #define check_add_overflow(a, b) __builtin_add_overflow_p(a, b, (typeof((a) + (b)))0)
-#define check_sub_overflow(a, b) __builtin_add_overflow_p(a, b, (typeof((a) - (b)))0)
-#define check_mul_overflow(a, b) __builtin_add_overflow_p(a, b, (typeof((a) * (b)))0)
+#define check_sub_overflow(a, b) __builtin_sub_overflow_p(a, b, (typeof((a) - (b)))0)
+#define check_mul_overflow(a, b) __builtin_mul_overflow_p(a, b, (typeof((a) * (b)))0)
 #else
 #define check_add_overflow(a, b) ({ (void)((int)(a) == (int)(b)); 0; })
 #define check_sub_overflow(a, b) ({ (void)((int)(a) == (int)(b)); 0; })
Signature · 1 line
2.31.1
Reviewed-by Daniele Ahmed on v1 1/2
#2 lore raw

Re: [PATCH kvm-unit-tests 1/2] compiler.h: Fix typos in mul and sub overflow checks

Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879

#3 lore raw

PATCH 2/2 lib: Introduce strtoll/strtoull

In reply to Andrew Jones
---
 lib/stdlib.h |  2 ++
 lib/string.c | 51 +++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 39 insertions(+), 14 deletions(-)
lib/stdlib.h +2 -0
index 33c00e8a5204..28496d7ae333 100644
@@ -9,5 +9,7 @@
 
 long int strtol(const char *nptr, char **endptr, int base);
 unsigned long int strtoul(const char *nptr, char **endptr, int base);
+long long int strtoll(const char *nptr, char **endptr, int base);
+unsigned long long int strtoull(const char *nptr, char **endptr, int base);
 
 #endif /* _STDLIB_H_ */
lib/string.c +37 -14

82 lines not on this page · raw message

Signature · 1 line
2.31.1
Reviewed-by Daniele Ahmed on v1 2/2
#4 lore raw

Re: [PATCH kvm-unit-tests 2/2] lib: Introduce strtoll/strtoull

Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879

maintainer Applied
#5 lore raw
In reply to Andrew Jones
Quoted 4 lines · Andrew Jones

A recent posting by Daniele Ahmed inspired me to write a patch adding strtoll/strtoull. While doing that I noticed check_mul_overflow wasn't working and found copy+paste errors with it and check_sub_overflow.

Quoted 9 lines

Andrew Jones (2):
compiler.h: Fix typos in mul and sub overflow checks
lib: Introduce strtoll/strtoull

  lib/linux/compiler.h |  4 ++--
  lib/stdlib.h         |  2 ++
  lib/string.c         | 51 ++++++++++++++++++++++++++++++++------------
  3 files changed, 41 insertions(+), 16 deletions(-)

Queued, thanks.

Paolo