changeset 922:32eec4a8f363

Force 64 bit math in expr, from Daniel Verkamp
author Rob Landley <rob@landley.net>
date Sat, 15 Jun 2013 00:49:06 -0500
parents 6a37f642b572
children aff9fa1075eb
files toys/pending/expr.c
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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));
 }