Skip to content

Commit

Permalink
spa: use strtoull for atou32
Browse files Browse the repository at this point in the history
On machines with a 32 bits long, converting a negative value will
still result in  v == (uint32_t)v and the unit test will fail.
Extend to 64 bits and strtoull to reject negative values in atou32.
  • Loading branch information
wtay committed Jun 3, 2021
1 parent 0b0a489 commit 3fcb9c4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions spa/include/spa/utils/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ static inline bool spa_atoi32(const char *str, int32_t *val, int base)
static inline bool spa_atou32(const char *str, uint32_t *val, int base)
{
char *endptr;
unsigned long v;
unsigned long long v;

if (!str || *str =='\0')
return false;

errno = 0;
v = strtoul(str, &endptr, base);
v = strtoull(str, &endptr, base);
if (errno != 0 || *endptr != '\0')
return false;

Expand Down

0 comments on commit 3fcb9c4

Please sign in to comment.