1
0
Fork 0
mirror of https://github.com/CTCaer/hekate.git synced 2024-11-26 11:42:09 +00:00

bdk: strtol: support unsigned 32bit hex

If base is 16 and input is not negative allow unsigned 32bit parsing.

This allows parsing numbers of up to 4294967295 in that case.
This commit is contained in:
CTCaer 2024-01-06 21:55:21 +02:00
parent dab5eb9aa0
commit c7333e710c

View file

@ -102,6 +102,7 @@ u64 sqrt64(u64 num)
return square_root; return square_root;
} }
#define TULONG_MAX ((unsigned long)((unsigned long)(~0L)))
#define TLONG_MAX ((long)(((unsigned long)(~0L)) >> 1)) #define TLONG_MAX ((long)(((unsigned long)(~0L)) >> 1))
#define TLONG_MIN ((long)(~TLONG_MAX)) #define TLONG_MIN ((long)(~TLONG_MAX))
#define ISSPACE(ch) ((ch >= '\t' && ch <= '\r') || (ch == ' ')) #define ISSPACE(ch) ((ch >= '\t' && ch <= '\r') || (ch == ' '))
@ -162,7 +163,7 @@ long strtol(const char *nptr, char **endptr, register int base)
* Set any if any `digits' consumed; make it negative to indicate * Set any if any `digits' consumed; make it negative to indicate
* overflow. * overflow.
*/ */
cutoff = neg ? -(unsigned long)TLONG_MIN : TLONG_MAX; cutoff = neg ? -(unsigned long)TLONG_MIN : (base == 16 ? TULONG_MAX : TLONG_MAX);
cutlim = cutoff % (unsigned long)base; cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base; cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) { for (acc = 0, any = 0;; c = *s++) {