diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2016-01-06 17:53:15 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2016-01-06 17:53:15 +0000 |
commit | 3f95096d910d253c4582596c259c314ae7079d79 (patch) | |
tree | a21e4dbdf2d253b2c40b0eb222d74476ac541a62 /bin/expr/expr.c | |
parent | 601340975d5c1ab46d70fdf578bc81f290b9ebfe (diff) |
use int64_t for arithmetic. 64 bits ought to be enough for anyone.
ok deraadt millert schwarze
Diffstat (limited to 'bin/expr/expr.c')
-rw-r--r-- | bin/expr/expr.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/bin/expr/expr.c b/bin/expr/expr.c index d0adf0520bd..acfebe3cc68 100644 --- a/bin/expr/expr.c +++ b/bin/expr/expr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expr.c,v 1.23 2015/12/29 19:06:16 gsoares Exp $ */ +/* $OpenBSD: expr.c,v 1.24 2016/01/06 17:53:14 tedu Exp $ */ /* $NetBSD: expr.c,v 1.3.6.1 1996/06/04 20:41:47 cgd Exp $ */ /* @@ -16,10 +16,10 @@ #include <regex.h> #include <err.h> -struct val *make_int(int); +struct val *make_int(int64_t); struct val *make_str(char *); void free_value(struct val *); -int is_integer(struct val *, int *); +int is_integer(struct val *, int64_t *); int to_integer(struct val *); void to_string(struct val *); int is_zero_or_null(struct val *); @@ -46,7 +46,7 @@ struct val { union { char *s; - int i; + int64_t i; } u; }; @@ -55,7 +55,7 @@ struct val *tokval; char **av; struct val * -make_int(int i) +make_int(int64_t i) { struct val *vp; @@ -94,11 +94,11 @@ free_value(struct val *vp) /* determine if vp is an integer; if so, return it's value in *r */ int -is_integer(struct val *vp, int *r) +is_integer(struct val *vp, int64_t *r) { char *s; int neg; - int i; + int64_t i; if (vp->type == integer) { *r = vp->u.i; @@ -138,7 +138,7 @@ is_integer(struct val *vp, int *r) int to_integer(struct val *vp) { - int r; + int64_t r; if (vp->type == integer) return 1; @@ -163,7 +163,7 @@ to_string(struct val *vp) if (vp->type == string) return; - if (asprintf(&tmp, "%d", vp->u.i) == -1) + if (asprintf(&tmp, "%lld", vp->u.i) == -1) err(3, NULL); vp->type = string; @@ -287,7 +287,7 @@ eval5(void) v = make_str(l->u.s + rm[1].rm_so); } else { - v = make_int((int)(rm[0].rm_eo - rm[0].rm_so)); + v = make_int(rm[0].rm_eo - rm[0].rm_so); } } else { if (rp.re_nsub == 0) { @@ -381,7 +381,7 @@ eval2(void) { struct val *l, *r; enum token op; - int v = 0, li, ri; + int64_t v = 0, li, ri; l = eval3(); while ((op = token) == EQ || op == NE || op == LT || op == GT || @@ -518,7 +518,7 @@ main(int argc, char *argv[]) } if (vp->type == integer) - printf("%d\n", vp->u.i); + printf("%lld\n", vp->u.i); else printf("%s\n", vp->u.s); |