pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Martin Pitt <mpitt@debian.org>
To: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Cc: Aurelien Jarno <aurel32@debian.org>
Cc: 616180@bugs.debian.org
Subject: [patch] test failure on sparc64 due to undefined division by zero behaviour
Date: Fri, 11 Mar 2011 18:47:10 +0100
Message-ID: <20110311174710.GF2541@piware.de> (raw)

Hello PostgreSQL hackers,

I recently got the following bug report about a test suite failure on
sparc64:

----- Forwarded message from Aurelien Jarno <aurel32@debian.org> -----

Date: Wed, 02 Mar 2011 23:49:05 +0100
From: Aurelien Jarno <aurel32@debian.org>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: Bug#616180: postgresql-9.0: FTBFS on sparc64, testsuite issues with int8

postgresql-9.0 fails to build on sparc64 due to testsuite errors with 
int8. The division by 0 is not trapped and a SIGFPE is issued instead of
an error.

Postgresql people claims it's a gcc bug, while gcc people says the code
is incorrect [1]. Whatever the real issue is, the fix is very simple 
(actually taken in another part from the very same file), so it's 
probably the best to simply apply it.

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29968

----- End forwarded message -----


The C99 standard [2], section 6.5.5 paragraph 5 actually says:

  "The result of the / operator is the quotient from the division of
  the first operand by the second; the result of the % operator is the
  remainder. In both operations, if the value of the second operand is
  zero, the behavior is undefined."

so the gcc folk's claim that this isn't a gcc bug looks justified.

Aurelien sent a straightforward patch for this, I updated it to apply
to current git head, updated the comments, and git-formatted it.

Thanks for considering!

Martin

[2] http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)

Attachments:

0001-Avoid-undefined-division-by-zero.patch (text/x-diff, 2.5K) download From 734d86c9482d545f38c9c51e173d7f2287f521bf Mon Sep 17 00:00:00 2001 From: Martin Pitt <mpitt@debian.org> Date: Fri, 11 Mar 2011 18:38:54 +0100 Subject: [PATCH] Avoid undefined division by zero Various division by zero operations in the test suite currently cause test failures on sparc64, as the compiler does not throw a SIGFPE like on most other platforms. Apply the already existing NULL returns from some division functions to int{8,82,84}div() as well, and update the comment to say that it isn't a gcc bug (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29968 and http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf section 6.5.5 paragraph 5). Thanks to Aurelien Jarno for the initial patch! --- src/backend/utils/adt/int8.c | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index bbab90c..d92b599 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -590,9 +590,13 @@ int8div(PG_FUNCTION_ARGS) int64 result; if (arg2 == 0) + { ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); + /* ensure we don't reach the division, as this is undefined */ + PG_RETURN_NULL(); + } result = arg1 / arg2; @@ -813,9 +817,13 @@ int84div(PG_FUNCTION_ARGS) int64 result; if (arg2 == 0) + { ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); + /* ensure we don't reach the division, as this is undefined */ + PG_RETURN_NULL(); + } result = arg1 / arg2; @@ -912,7 +920,7 @@ int48div(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); - /* ensure compiler realizes we mustn't reach the division (gcc bug) */ + /* ensure we don't reach the division, as this is undefined */ PG_RETURN_NULL(); } @@ -997,9 +1005,13 @@ int82div(PG_FUNCTION_ARGS) int64 result; if (arg2 == 0) + { ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); + /* ensure we don't reach the division, as this is undefined */ + PG_RETURN_NULL(); + } result = arg1 / arg2; @@ -1096,7 +1108,7 @@ int28div(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_DIVISION_BY_ZERO), errmsg("division by zero"))); - /* ensure compiler realizes we mustn't reach the division (gcc bug) */ + /* ensure we don't reach the division, as this is undefined */ PG_RETURN_NULL(); } -- 1.7.4.1
signature.asc (application/pgp-signature, 835B) download

view thread (2+ messages)  latest in thread

Message-ID: <20110311174710.GF2541@piware.de>
Permalink:  ../20110311174710.GF2541@piware.de/
Also on:    postgresql.org/message-id/20110311174710.GF2541@piware.de

 ·  · 

reply

Reply instructions:

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

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: mpitt@debian.org, aurel32@debian.org, 616180@bugs.debian.org
  Subject: Re: [patch] test failure on sparc64 due to undefined division by zero behaviour
  In-Reply-To: <20110311174710.GF2541@piware.de>
  References: <20110311174710.GF2541@piware.de>

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

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox