mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
fix bug in new str -> num convertors
This commit is contained in:
parent
7df69b887a
commit
df38188367
@ -49,6 +49,7 @@ static unsigned long long handle_errors(unsigned long long v, char **endp, char
|
|||||||
|
|
||||||
unsigned long long bb_strtoull(const char *arg, char **endp, int base)
|
unsigned long long bb_strtoull(const char *arg, char **endp, int base)
|
||||||
{
|
{
|
||||||
|
unsigned long long v;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
|
||||||
/* strtoul(" -4200000000") returns 94967296, errno 0 (!) */
|
/* strtoul(" -4200000000") returns 94967296, errno 0 (!) */
|
||||||
@ -57,35 +58,42 @@ unsigned long long bb_strtoull(const char *arg, char **endp, int base)
|
|||||||
|
|
||||||
/* not 100% correct for lib func, but convenient for the caller */
|
/* not 100% correct for lib func, but convenient for the caller */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
return handle_errors(strtoull(arg, &endptr, base), endp, endptr);
|
v = strtoull(arg, &endptr, base);
|
||||||
|
return handle_errors(v, endp, endptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
long long bb_strtoll(const char *arg, char **endp, int base)
|
long long bb_strtoll(const char *arg, char **endp, int base)
|
||||||
{
|
{
|
||||||
|
unsigned long long v;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
|
||||||
if (arg[0] != '-' && !isalnum(arg[0])) return ret_ERANGE();
|
if (arg[0] != '-' && !isalnum(arg[0])) return ret_ERANGE();
|
||||||
errno = 0;
|
errno = 0;
|
||||||
return handle_errors(strtoll(arg, &endptr, base), endp, endptr);
|
v = strtoll(arg, &endptr, base);
|
||||||
|
return handle_errors(v, endp, endptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ULONG_MAX != ULLONG_MAX
|
#if ULONG_MAX != ULLONG_MAX
|
||||||
unsigned long bb_strtoul(const char *arg, char **endp, int base)
|
unsigned long bb_strtoul(const char *arg, char **endp, int base)
|
||||||
{
|
{
|
||||||
|
unsigned long v;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
|
||||||
if (!isalnum(arg[0])) return ret_ERANGE();
|
if (!isalnum(arg[0])) return ret_ERANGE();
|
||||||
errno = 0;
|
errno = 0;
|
||||||
return handle_errors(strtoul(arg, &endptr, base), endp, endptr);
|
v = strtoul(arg, &endptr, base);
|
||||||
|
return handle_errors(v, endp, endptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
long bb_strtol(const char *arg, char **endp, int base)
|
long bb_strtol(const char *arg, char **endp, int base)
|
||||||
{
|
{
|
||||||
|
long v;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
|
||||||
if (arg[0] != '-' && !isalnum(arg[0])) return ret_ERANGE();
|
if (arg[0] != '-' && !isalnum(arg[0])) return ret_ERANGE();
|
||||||
errno = 0;
|
errno = 0;
|
||||||
return handle_errors(strtol(arg, &endptr, base), endp, endptr);
|
v = strtol(arg, &endptr, base);
|
||||||
|
return handle_errors(v, endp, endptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user