From 222a5ec993d3ea7dd636a48848d2e5352ed9d8f8 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Fri, 24 Dec 2010 13:53:20 +0100 Subject: [PATCH] cmdline (merge-intel): use maximum int values defines from stdint.h Signed-off-by: Olivier Matz --- src/lib/cmdline_parse_num.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/lib/cmdline_parse_num.c b/src/lib/cmdline_parse_num.c index 90c9402..6d7adb5 100644 --- a/src/lib/cmdline_parse_num.c +++ b/src/lib/cmdline_parse_num.c @@ -26,6 +26,7 @@ */ #include +#include #include #include #include @@ -36,21 +37,6 @@ //#define debug_printf(args...) printf(args) #define debug_printf(args...) do {} while(0) -/* XXX to remove ? there should be something better */ -#define U08_MIN 0x00 -#define U08_MAX 0xFF -#define U16_MIN 0x0000 -#define U16_MAX 0xFFFF -#define U32_MIN 0x00000000 -#define U32_MAX 0xFFFFFFFF -#define S08_MIN 0x80 -#define S08_MAX 0x7F -#define S16_MIN 0x8000 -#define S16_MAX 0x7FFF -#define S32_MIN 0x80000000 -#define S32_MAX 0x7FFFFFFF - - struct cmdline_token_ops cmdline_token_num_ops = { .parse = cmdline_parse_num, .complete_get_nb = NULL, @@ -93,7 +79,7 @@ static inline int add_to_res(unsigned int c, unsigned int *res, unsigned int base) { /* overflow */ - if ( (U32_MAX - c) / base < *res ) { + if ( (UINT32_MAX - c) / base < *res ) { return -1; } @@ -339,27 +325,27 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) case HEX_OK: case OCTAL_OK: case BIN_OK: - if ( nd.type == INT8 && res1 <= S08_MAX ) { + if ( nd.type == INT8 && res1 <= INT8_MAX ) { if (res) *(int8_t *)res = (int8_t) res1; return (buf-srcbuf); } - else if ( nd.type == INT16 && res1 <= S16_MAX ) { + else if ( nd.type == INT16 && res1 <= INT16_MAX ) { if (res) *(int16_t *)res = (int16_t) res1; return (buf-srcbuf); } - else if ( nd.type == INT32 && res1 <= S32_MAX ) { + else if ( nd.type == INT32 && res1 <= INT32_MAX ) { if (res) *(int32_t *)res = (int32_t) res1; return (buf-srcbuf); } - else if ( nd.type == UINT8 && res1 <= U08_MAX ) { + else if ( nd.type == UINT8 && res1 <= UINT8_MAX ) { if (res) *(uint8_t *)res = (uint8_t) res1; return (buf-srcbuf); } - else if (nd.type == UINT16 && res1 <= U16_MAX ) { + else if (nd.type == UINT16 && res1 <= UINT16_MAX ) { if (res) *(uint16_t *)res = (uint16_t) res1; return (buf-srcbuf); @@ -382,17 +368,17 @@ cmdline_parse_num(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res) break; case DEC_NEG_OK: - if ( nd.type == INT8 && res1 <= S08_MAX + 1 ) { + if ( nd.type == INT8 && res1 <= INT8_MAX + 1 ) { if (res) *(int8_t *)res = - (int8_t) res1; return (buf-srcbuf); } - else if ( nd.type == INT16 && res1 <= (uint16_t)S16_MAX + 1 ) { + else if ( nd.type == INT16 && res1 <= (uint16_t)INT16_MAX + 1 ) { if (res) *(int16_t *)res = - (int16_t) res1; return (buf-srcbuf); } - else if ( nd.type == INT32 && res1 <= (uint32_t)S32_MAX + 1 ) { + else if ( nd.type == INT32 && res1 <= (uint32_t)INT32_MAX + 1 ) { if (res) *(int32_t *)res = - (int32_t) res1; return (buf-srcbuf); -- 2.20.1