# HG changeset patch # User Rob Landley # Date 1371275346 18000 # Node ID 32eec4a8f36383619f8f330faccd62f4f518801e # Parent 6a37f642b5721026bf156c2c241c06017abbbaa1 Force 64 bit math in expr, from Daniel Verkamp diff -r 6a37f642b572 -r 32eec4a8f363 toys/pending/expr.c --- a/toys/pending/expr.c Sat Jun 08 14:11:41 2013 -0500 +++ b/toys/pending/expr.c Sat Jun 15 00:49:06 2013 -0500 @@ -36,7 +36,7 @@ // If s is not NULL, the value is a string (s). struct value { char *s; - long i; + long long i; }; static void parse_expr(struct value *ret, struct value *v); @@ -57,7 +57,7 @@ arg = toys.optargs[TT.argidx++]; - v->i = strtol(arg, &endp, 10); + v->i = strtoll(arg, &endp, 10); v->s = *endp ? arg : NULL; } @@ -79,10 +79,10 @@ return ((v->s && *v->s == '\0') || v->i == 0); } -static char *num_to_str(long num) +static char *num_to_str(long long num) { static char num_buf[21]; - snprintf(num_buf, sizeof(num_buf), "%ld", num); + snprintf(num_buf, sizeof(num_buf), "%lld", num); return num_buf; } @@ -266,7 +266,7 @@ if (!tok.s || *tok.s) error_exit("syntax error"); // final token should be end of expression if (ret.s) printf("%s\n", ret.s); - else printf("%ld\n", ret.i); + else printf("%lld\n", ret.i); exit(is_zero(&ret)); }