This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[Patch] x % 0 hangs
- From: David Lecomber <david at streamline-computing dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sat, 26 Jun 2004 10:35:29 +0100
- Subject: [Patch] x % 0 hangs
Hi
On my x86, gdb does not enjoy evaluating x % 0 or x / 0 for any x: it
hangs.
Although there may be some systems that can healthily respond to this, I
propose a trivial patch - unless someone is going to tell me there's an
option to stop the hanging, or respond differently to the signal.
2004-06-26 <david@streamline-computing.com>
* valarith.c: check for zero in division and remainder
evaluation.
Index: valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.22
diff -u -p -r1.22 valarith.c
--- valarith.c 1 Apr 2004 12:08:30 -0000 1.22
+++ valarith.c 26 Jun 2004 09:21:31 -0000
@@ -1040,7 +1040,10 @@ value_binop (struct value *arg1, struct
break;
case BINOP_DIV:
- v = v1 / v2;
+ if (v2 != 0)
+ v = v1 / v2;
+ else
+ error ("Cannot perform division: division by zero");
break;
case BINOP_EXP:
@@ -1050,7 +1053,10 @@ value_binop (struct value *arg1, struct
break;
case BINOP_REM:
- v = v1 % v2;
+ if (v2 != 0)
+ v = v1 % v2;
+ else
+ error ("Cannot perform remainer: division by zero");
break;
case BINOP_MOD: