Commit 0d749d60 authored by James Zern's avatar James Zern
Browse files

args.c: fix range check in int/uint

this also clears the remaining -Wshorten-64-to-32 warnings in this file.
the previous patch ported from libvpx was incomplete due to:
d3a7576f Add compiler flag -Wsign-compare

Change-Id: I105fa2342073dfa8bd0619b4282435fb6568f5c9
parent 223b90e5
...@@ -120,15 +120,13 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs) { ...@@ -120,15 +120,13 @@ void arg_show_usage(FILE *fp, const struct arg_def *const *defs) {
} }
unsigned int arg_parse_uint(const struct arg *arg) { unsigned int arg_parse_uint(const struct arg *arg) {
uint32_t rawval;
char *endptr; char *endptr;
const unsigned long rawval = strtoul(arg->val, &endptr, 10); // NOLINT
rawval = strtoul(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0') { if (arg->val[0] != '\0' && endptr[0] == '\0') {
if (rawval <= UINT_MAX) return (unsigned int)rawval; if (rawval <= UINT_MAX) return (unsigned int)rawval;
die("Option %s: Value %ld out of range for unsigned int\n", arg->name, die("Option %s: Value %lu out of range for unsigned int\n", arg->name,
rawval); rawval);
} }
...@@ -137,10 +135,8 @@ unsigned int arg_parse_uint(const struct arg *arg) { ...@@ -137,10 +135,8 @@ unsigned int arg_parse_uint(const struct arg *arg) {
} }
int arg_parse_int(const struct arg *arg) { int arg_parse_int(const struct arg *arg) {
int32_t rawval;
char *endptr; char *endptr;
const long rawval = strtol(arg->val, &endptr, 10); // NOLINT
rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0') { if (arg->val[0] != '\0' && endptr[0] == '\0') {
if (rawval >= INT_MIN && rawval <= INT_MAX) return (int)rawval; if (rawval >= INT_MIN && rawval <= INT_MAX) return (int)rawval;
......
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