Skip to content
Snippets Groups Projects
Commit dec3b242 authored by Michael Tüxen's avatar Michael Tüxen
Browse files

Use appropriate constants for range check.

parent fdca75bc
No related branches found
No related tags found
No related merge requests found
...@@ -181,18 +181,18 @@ static int check_type(struct expression *expression, ...@@ -181,18 +181,18 @@ static int check_type(struct expression *expression,
} }
/* Sets the value from the expression argument, checking that it is a /* Sets the value from the expression argument, checking that it is a
* valid u16, and matches the expected type. Returns STATUS_OK on * valid u32, and matches the expected type. Returns STATUS_OK on
* success; on failure returns STATUS_ERR and sets error message. * success; on failure returns STATUS_ERR and sets error message.
*/ */
static int get_u16(struct expression *expression, static int get_u32(struct expression *expression,
u16 *value, char **error) u32 *value, char **error)
{ {
if (check_type(expression, EXPR_INTEGER, error)) if (check_type(expression, EXPR_INTEGER, error))
return STATUS_ERR; return STATUS_ERR;
if ((expression->value.num > UINT16_MAX) || if ((expression->value.num > UINT32_MAX) ||
(expression->value.num < 0)) { (expression->value.num < 0)) {
asprintf(error, asprintf(error,
"Value out of range for 16-bit unsigned integer: %lld", "Value out of range for 32-bit unsigned integer: %lld",
expression->value.num); expression->value.num);
return STATUS_ERR; return STATUS_ERR;
} }
...@@ -201,18 +201,18 @@ static int get_u16(struct expression *expression, ...@@ -201,18 +201,18 @@ static int get_u16(struct expression *expression,
} }
/* Sets the value from the expression argument, checking that it is a /* Sets the value from the expression argument, checking that it is a
* valid u32, and matches the expected type. Returns STATUS_OK on * valid s32 or u32, and matches the expected type. Returns STATUS_OK on
* success; on failure returns STATUS_ERR and sets error message. * success; on failure returns STATUS_ERR and sets error message.
*/ */
static int get_u32(struct expression *expression, static int get_s32(struct expression *expression,
u32 *value, char **error) s32 *value, char **error)
{ {
if (check_type(expression, EXPR_INTEGER, error)) if (check_type(expression, EXPR_INTEGER, error))
return STATUS_ERR; return STATUS_ERR;
if ((expression->value.num > UINT32_MAX) || if ((expression->value.num > UINT_MAX) ||
(expression->value.num < 0)) { (expression->value.num < INT_MIN)) {
asprintf(error, asprintf(error,
"Value out of range for 32-bit unsigned integer: %lld", "Value out of range for 32-bit integer: %lld",
expression->value.num); expression->value.num);
return STATUS_ERR; return STATUS_ERR;
} }
...@@ -221,18 +221,18 @@ static int get_u32(struct expression *expression, ...@@ -221,18 +221,18 @@ static int get_u32(struct expression *expression,
} }
/* Sets the value from the expression argument, checking that it is a /* Sets the value from the expression argument, checking that it is a
* valid s32 or u32, and matches the expected type. Returns STATUS_OK on * valid u16, and matches the expected type. Returns STATUS_OK on
* success; on failure returns STATUS_ERR and sets error message. * success; on failure returns STATUS_ERR and sets error message.
*/ */
static int get_s32(struct expression *expression, static int get_u16(struct expression *expression,
s32 *value, char **error) u16 *value, char **error)
{ {
if (check_type(expression, EXPR_INTEGER, error)) if (check_type(expression, EXPR_INTEGER, error))
return STATUS_ERR; return STATUS_ERR;
if ((expression->value.num > UINT_MAX) || if ((expression->value.num > UINT16_MAX) ||
(expression->value.num < INT_MIN)) { (expression->value.num < 0)) {
asprintf(error, asprintf(error,
"Value out of range for 32-bit integer: %lld", "Value out of range for 16-bit unsigned integer: %lld",
expression->value.num); expression->value.num);
return STATUS_ERR; return STATUS_ERR;
} }
...@@ -249,8 +249,8 @@ static int get_s16(struct expression *expression, ...@@ -249,8 +249,8 @@ static int get_s16(struct expression *expression,
{ {
if (check_type(expression, EXPR_INTEGER, error)) if (check_type(expression, EXPR_INTEGER, error))
return STATUS_ERR; return STATUS_ERR;
if ((expression->value.num > USHRT_MAX) || if ((expression->value.num > INT16_MAX) ||
(expression->value.num < SHRT_MIN)) { (expression->value.num < INT16_MIN)) {
asprintf(error, asprintf(error,
"Value out of range for 16-bit integer: %lld", "Value out of range for 16-bit integer: %lld",
expression->value.num); expression->value.num);
...@@ -269,8 +269,8 @@ static int get_s8(struct expression *expression, ...@@ -269,8 +269,8 @@ static int get_s8(struct expression *expression,
{ {
if (check_type(expression, EXPR_INTEGER, error)) if (check_type(expression, EXPR_INTEGER, error))
return STATUS_ERR; return STATUS_ERR;
if ((expression->value.num > UCHAR_MAX) || if ((expression->value.num > INT8_MAX) ||
(expression->value.num < SCHAR_MIN)) { (expression->value.num < INT8_MIN)) {
asprintf(error, asprintf(error,
"Value out of range for 8-bit integer: %lld", "Value out of range for 8-bit integer: %lld",
expression->value.num); expression->value.num);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment