summaryrefslogtreecommitdiff
path: root/usr.bin/pcc/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/pcc/cpp')
-rw-r--r--usr.bin/pcc/cpp/cpp.c19
-rw-r--r--usr.bin/pcc/cpp/cpp.h3
-rw-r--r--usr.bin/pcc/cpp/cpy.y15
3 files changed, 33 insertions, 4 deletions
diff --git a/usr.bin/pcc/cpp/cpp.c b/usr.bin/pcc/cpp/cpp.c
index 74005f0b045..4506592c717 100644
--- a/usr.bin/pcc/cpp/cpp.c
+++ b/usr.bin/pcc/cpp/cpp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpp.c,v 1.2 2007/10/07 19:26:27 otto Exp $ */
+/* $OpenBSD: cpp.c,v 1.3 2007/10/12 18:14:14 stefan Exp $ */
/*
* Copyright (c) 2004 Anders Magnusson (ragge@ludd.luth.se).
@@ -728,6 +728,23 @@ bad: error("bad define");
}
void
+warning(usch *s)
+{
+ usch *t;
+ usch *sb = stringbuf;
+
+ flbuf();
+ savch(0);
+ if (ifiles != NULL) {
+ t = sheap("%s:%d: warning: ", ifiles->fname, ifiles->lineno);
+ write (2, t, strlen((char *)t));
+ }
+ write (2, s, strlen((char *)s));
+ write (2, "\n", 1);
+ stringbuf = sb;
+}
+
+void
xerror(usch *s)
{
usch *t;
diff --git a/usr.bin/pcc/cpp/cpp.h b/usr.bin/pcc/cpp/cpp.h
index d12968dcf08..d3e7773a522 100644
--- a/usr.bin/pcc/cpp/cpp.h
+++ b/usr.bin/pcc/cpp/cpp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpp.h,v 1.2 2007/10/12 07:22:44 otto Exp $ */
+/* $OpenBSD: cpp.h,v 1.3 2007/10/12 18:14:14 stefan Exp $ */
/*
* Copyright (c) 2004 Anders Magnusson (ragge@ludd.luth.se).
@@ -143,6 +143,7 @@ void putch(int);
void putstr(usch *s);
void line(void);
usch *sheap(char *fmt, ...);
+void warning(usch *);
void xerror(usch *);
#define error(...) xerror(sheap(__VA_ARGS__))
void expmac(struct recur *);
diff --git a/usr.bin/pcc/cpp/cpy.y b/usr.bin/pcc/cpp/cpy.y
index ed73fceebcc..37ba7371fbc 100644
--- a/usr.bin/pcc/cpp/cpy.y
+++ b/usr.bin/pcc/cpp/cpy.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpy.y,v 1.2 2007/10/12 07:22:44 otto Exp $ */
+/* $OpenBSD: cpy.y,v 1.3 2007/10/12 18:14:14 stefan Exp $ */
/*
* Copyright (c) 2004 Anders Magnusson (ragge@ludd.luth.se).
@@ -275,6 +275,18 @@ eval(struct nd *tree)
l = eval(tree->nd_left);
r = eval(tree->nd_right);
t = l.type || r.type;
+ if (tree->op == '/' || tree->op == '%') {
+ if ((t && r.v.uval == 0) || (!t && r.v.val == 0)) {
+ warning(tree->op == '/' ? "division by zero" :
+ "modulus by zero");
+ if (t)
+ ret.v.uval = 0;
+ else
+ ret.v.val = 0;
+ ret.type = t;
+ goto out;
+ }
+ }
switch (tree->op) {
EVALBIN(EQ, ==, t, l, r, 0);
EVALBIN(NE, !=, t, l, r, 0);
@@ -285,7 +297,6 @@ eval(struct nd *tree)
EVALBIN('+', +, t, l, r, t);
EVALBIN('-', -, t, l, r, t);
EVALBIN('*', *, t, l, r, t);
- // XXX check /,% by zero
EVALBIN('/', /, t, l, r, t);
EVALBIN('%', %, t, l, r, t);
EVALBIN('&', &, t, l, r, t);