Commit 6720b699 authored by Daniel Salzman's avatar Daniel Salzman

strtonum: mute some clang analyzer warnings

parent a8baf411
......@@ -25,7 +25,7 @@
#include "libknot/errcode.h"
#include "contrib/ctype.h"
inline static int intmax_from_str(const char *src, intmax_t *dest,
inline static int intmax_from_str(const char *src, intmax_t *dst,
intmax_t min, intmax_t max)
{
if (!is_digit(*src) && *src != '-' && *src != '+') {
......@@ -48,11 +48,11 @@ inline static int intmax_from_str(const char *src, intmax_t *dest,
return KNOT_ERANGE;
}
*dest = result;
*dst = result;
return KNOT_EOK;
}
inline static int uintmax_from_str(const char *src, uintmax_t *dest,
inline static int uintmax_from_str(const char *src, uintmax_t *dst,
uintmax_t min, uintmax_t max)
{
if (!is_digit(*src) && *src != '+') {
......@@ -75,44 +75,45 @@ inline static int uintmax_from_str(const char *src, uintmax_t *dest,
return KNOT_ERANGE;
}
*dest = result;
*dst = result;
return KNOT_EOK;
}
#define CONVERT(prefix, type, min, max, src, dest) \
#define CONVERT(prefix, type, min, max, src, dst) \
{ \
assert(src && dst); \
prefix##max_t value; \
int result = prefix##max_from_str(src, &value, min, max); \
if (result != KNOT_EOK) { \
return result; \
} \
*dest = (type)value; \
*dst = (type)value; \
return KNOT_EOK; \
}
inline static int str_to_int(const char *src, int *dest, int min, int max)
inline static int str_to_int(const char *src, int *dst, int min, int max)
{
CONVERT(int, int, min, max, src, dest);
CONVERT(int, int, min, max, src, dst);
}
inline static int str_to_u8(const char *src, uint8_t *dest)
inline static int str_to_u8(const char *src, uint8_t *dst)
{
CONVERT(uint, uint8_t, 0, UINT8_MAX, src, dest);
CONVERT(uint, uint8_t, 0, UINT8_MAX, src, dst);
}
inline static int str_to_u16(const char *src, uint16_t *dest)
inline static int str_to_u16(const char *src, uint16_t *dst)
{
CONVERT(uint, uint16_t, 0, UINT16_MAX, src, dest);
CONVERT(uint, uint16_t, 0, UINT16_MAX, src, dst);
}
inline static int str_to_u32(const char *src, uint32_t *dest)
inline static int str_to_u32(const char *src, uint32_t *dst)
{
CONVERT(uint, uint32_t, 0, UINT32_MAX, src, dest);
CONVERT(uint, uint32_t, 0, UINT32_MAX, src, dst);
}
inline static int str_to_size(const char *src, size_t *dest, size_t min, size_t max)
inline static int str_to_size(const char *src, size_t *dst, size_t min, size_t max)
{
CONVERT(uint, size_t, min, max, src, dest);
CONVERT(uint, size_t, min, max, src, dst);
}
#undef CONVERT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment