Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: David Lecomber <david@streamline-computing.com>
To: gdb-patches@sources.redhat.com
Subject: [Patch] x % 0 hangs
Date: Sat, 26 Jun 2004 09:23:00 -0000	[thread overview]
Message-ID: <1088242528.30850.78.camel@cpc4-oxfd5-5-0-cust12.oxfd.cable.ntl.com> (raw)

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:



             reply	other threads:[~2004-06-26  9:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-26  9:23 David Lecomber [this message]
2004-06-26 15:44 Michael Elizabeth Chastain
2004-06-26 22:52 ` Mark Kettenis
2004-06-26 23:19   ` Andrew Cagney
2004-06-27 15:06     ` Ian Lance Taylor
2004-06-27 17:15       ` Mark Kettenis
2004-06-28 14:25         ` Andrew Cagney
2004-06-29 23:35           ` Mark Kettenis
2004-07-17  2:43             ` Andrew Cagney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1088242528.30850.78.camel@cpc4-oxfd5-5-0-cust12.oxfd.cable.ntl.com \
    --to=david@streamline-computing.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox