public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Tom Tromey <tromey@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Handle fixed-point division by zero
Date: Sun, 13 Dec 2020 18:01:36 +0400	[thread overview]
Message-ID: <20201213140136.GH366101@adacore.com> (raw)
In-Reply-To: <20201211151548.732285-1-tromey@adacore.com>

Hi Tom,

On Fri, Dec 11, 2020 at 08:15:48AM -0700, Tom Tromey wrote:
> fixed_point_binop did not account for division by zero.  This would
> lead to gdb getting SIGFPE and subsequently cause some test cases to
> hang.
> 
> gdb/ChangeLog
> 2020-12-11  Tom Tromey  <tromey@adacore.com>
> 
> 	* valarith.c (fixed_point_binop): Call error on division by zero.
> 
> gdb/testsuite/ChangeLog
> 2020-12-11  Tom Tromey  <tromey@adacore.com>
> 
> 	* gdb.dwarf2/dw2-fixed-point.exp: Add test for division by zero.

Thanks for the patch. It looks good to me.

(sooo obvious in hindsight...)


> ---
>  gdb/ChangeLog                                | 4 ++++
>  gdb/testsuite/ChangeLog                      | 4 ++++
>  gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp | 3 +++
>  gdb/valarith.c                               | 2 ++
>  4 files changed, 13 insertions(+)
> 
> diff --git a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp
> index 67d1d34d8f3..2c859d1fd16 100644
> --- a/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp
> +++ b/gdb/testsuite/gdb.dwarf2/dw2-fixed-point.exp
> @@ -164,6 +164,9 @@ gdb_test "print pck.fp3_var * 1" \
>  gdb_test "print pck.fp3_var / pck.fp3_var" \
>           " = 1"
>  
> +gdb_test "print pck.fp3_var / 0" \
> +         "Division by zero"
> +
>  gdb_test "print pck.fp1_range_var - 0.5" \
>           " = 0.5"
>  
> diff --git a/gdb/valarith.c b/gdb/valarith.c
> index 37988f1dfa7..6854d9b80f0 100644
> --- a/gdb/valarith.c
> +++ b/gdb/valarith.c
> @@ -965,6 +965,8 @@ fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
>        break;
>  
>      case BINOP_DIV:
> +      if (mpq_sgn (v2.val) == 0)
> +	error (_("Division by zero"));
>        mpq_div (res.val, v1.val, v2.val);
>        val = fixed_point_to_value (res);
>        break;
> -- 
> 2.26.2

-- 
Joel

      reply	other threads:[~2020-12-13 14:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 15:15 Tom Tromey
2020-12-13 14:01 ` Joel Brobecker [this message]

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=20201213140136.GH366101@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).