X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fopt%2Fhelpers.c;h=420a97a4fcac596fd31999ffbda42bb229a7f0f3;hb=140cd1699215bdb2a849459644823b88ab7d42cf;hp=53fb0158827aca291e5ce39ff5566da60f49c8ec;hpb=bbdf3ef3c2c14e515388c6146fd00557cee905a1;p=ccan diff --git a/ccan/opt/helpers.c b/ccan/opt/helpers.c index 53fb0158..420a97a4 100644 --- a/ccan/opt/helpers.c +++ b/ccan/opt/helpers.c @@ -66,8 +66,8 @@ char *opt_set_intval(const char *arg, int *i) if (err) return err; *i = l; - /* Beware truncation... */ - if (*i != l) + /* Beware truncation, but don't generate untestable code. */ + if (sizeof(*i) != sizeof(l) && *i != l) return arg_bad("value '%s' does not fit into an integer", arg); return err; } @@ -258,7 +258,8 @@ static char * set_long_with_suffix(const char *arg, long *l, const long base) return err; *l = ll; - if (*l != ll) + /* Beware truncation, but don't generate untestable code. */ + if (sizeof(*l) != sizeof(ll) && *l != ll) return arg_bad("value '%s' does not fit into a long", arg); return NULL; } @@ -272,7 +273,8 @@ static char * set_ulong_with_suffix(const char *arg, unsigned long *ul, const lo if (ll < 0) return arg_bad("'%s' is negative but destination is unsigned", arg); *ul = ll; - if (*ul != ll) + /* Beware truncation, but don't generate untestable code. */ + if (sizeof(*ul) != sizeof(ll) && *ul != ll) return arg_bad("value '%s' does not fit into an unsigned long", arg); return NULL; }