ref: d772d55704dad4e5c15c296097ceb2d6b408f572
parent: c79665d0ada48bc0253167d403e7f91a5e74d11d
author: James Zern <jzern@google.com>
date: Thu Aug 4 19:23:00 EDT 2016
args.c: add some explicit casts values are range checked before returning; quiets -Wshorten-64-to-32 warnings Change-Id: I806af11b2aaf6760c7ab234a2fe2fdf40e7bece7
--- a/args.c
+++ b/args.c
@@ -124,7 +124,7 @@
rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0') {
- if (rawval >= 0 && rawval <= UINT_MAX) return rawval;
+ if (rawval >= 0 && rawval <= UINT_MAX) return (unsigned int)rawval;
die("Option %s: Value %ld out of range for unsigned int\n", arg->name,
rawval);
@@ -141,7 +141,7 @@
rawval = strtol(arg->val, &endptr, 10);
if (arg->val[0] != '\0' && endptr[0] == '\0') {
- if (rawval >= INT_MIN && rawval <= INT_MAX) return rawval;
+ if (rawval >= INT_MIN && rawval <= INT_MAX) return (int)rawval;
die("Option %s: Value %ld out of range for signed int\n", arg->name,
rawval);
@@ -165,7 +165,7 @@
if (arg->val[0] != '\0' && endptr[0] == '/') {
if (rawval >= INT_MIN && rawval <= INT_MAX)
- rat.num = rawval;
+ rat.num = (int)rawval;
else
die("Option %s: Value %ld out of range for signed int\n", arg->name,
rawval);
@@ -177,7 +177,7 @@
if (arg->val[0] != '\0' && endptr[0] == '\0') {
if (rawval >= INT_MIN && rawval <= INT_MAX)
- rat.den = rawval;
+ rat.den = (int)rawval;
else
die("Option %s: Value %ld out of range for signed int\n", arg->name,
rawval);
@@ -197,7 +197,7 @@
if (arg->val[0] != '\0' && endptr[0] == '\0') {
/* Got a raw value, make sure it's valid */
for (listptr = arg->def->enums; listptr->name; listptr++)
- if (listptr->val == rawval) return rawval;
+ if (listptr->val == rawval) return (int)rawval;
}
/* Next see if it can be parsed as a string */