mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-05 10:48:09 -05:00
Add safe_hextou32()
This commit is contained in:
parent
6867ae4c16
commit
f38ff924d7
36
src/misc.c
36
src/misc.c
@ -109,6 +109,42 @@ safe_atou32(const char *str, uint32_t *val)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
safe_hextou32(const char *str, uint32_t *val)
|
||||||
|
{
|
||||||
|
char *end;
|
||||||
|
unsigned long intval;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
intval = strtoul(str, &end, 16);
|
||||||
|
|
||||||
|
if (((errno == ERANGE) && (intval == ULONG_MAX))
|
||||||
|
|| ((errno != 0) && (intval == 0)))
|
||||||
|
{
|
||||||
|
DPRINTF(E_DBG, L_MISC, "Invalid integer in string (%s): %s\n", str, strerror(errno));
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end == str)
|
||||||
|
{
|
||||||
|
DPRINTF(E_DBG, L_MISC, "No integer found in string (%s)\n", str);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (intval > UINT32_MAX)
|
||||||
|
{
|
||||||
|
DPRINTF(E_DBG, L_MISC, "Integer value too large (%s)\n", str);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*val = (uint32_t)intval;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
safe_atoi64(const char *str, int64_t *val)
|
safe_atoi64(const char *str, int64_t *val)
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,9 @@ safe_atoi32(const char *str, int32_t *val);
|
|||||||
int
|
int
|
||||||
safe_atou32(const char *str, uint32_t *val);
|
safe_atou32(const char *str, uint32_t *val);
|
||||||
|
|
||||||
|
int
|
||||||
|
safe_hextou32(const char *str, uint32_t *val);
|
||||||
|
|
||||||
int
|
int
|
||||||
safe_atoi64(const char *str, int64_t *val);
|
safe_atoi64(const char *str, int64_t *val);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user