projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fc without arguments dereferences argv[1]; from Christos
[unix-history]
/
usr
/
src
/
bin
/
expr
/
expr.y
diff --git
a/usr/src/bin/expr/expr.y
b/usr/src/bin/expr/expr.y
index
f9af96c
..
cf3fa84
100644
(file)
--- a/
usr/src/bin/expr/expr.y
+++ b/
usr/src/bin/expr/expr.y
@@
-2,7
+2,7
@@
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
*
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
*
- * %sccs.include.
redist
.c%
+ * %sccs.include.
proprietary
.c%
*/
/* Yacc productions for "expr" command: */
*/
/* Yacc productions for "expr" command: */
@@
-66,7
+66,7
@@
char copyright[] =
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)expr.y 5.
1
(Berkeley) %G%";
+static char sccsid[] = "@(#)expr.y 5.
3
(Berkeley) %G%";
#endif /* not lint */
#include <stdio.h>
#endif /* not lint */
#include <stdio.h>
@@
-145,8
+145,18
@@
char *arith(op, r1, r2) char *r1, *r2; {
case ADD: i1 = i1 + i2; break;
case SUBT: i1 = i1 - i2; break;
case MULT: i1 = i1 * i2; break;
case ADD: i1 = i1 + i2; break;
case SUBT: i1 = i1 - i2; break;
case MULT: i1 = i1 * i2; break;
- case DIV: i1 = i1 / i2; break;
- case REM: i1 = i1 % i2; break;
+ case DIV:
+ if (i2 != 0)
+ i1 = i1 / i2;
+ else
+ yyerror("Divide by zero");
+ break;
+ case REM:
+ if (i2 != 0)
+ i1 = i1 % i2;
+ else
+ yyerror("Remainder by zero");
+ break;
}
rv = malloc(16);
(void)sprintf(rv, "%ld", i1);
}
rv = malloc(16);
(void)sprintf(rv, "%ld", i1);