Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 38CBE1337B80 for ; Fri, 11 Mar 2011 13:47:28 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 78403-06 for ; Fri, 11 Mar 2011 17:47:14 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.piware.de (unknown [213.9.93.70]) by mail.postgresql.org (Postfix) with ESMTP id A7695133616B for ; Fri, 11 Mar 2011 13:47:13 -0400 (AST) Received: from localhost.localdomain (pD9EB4CEA.dip.t-dialin.net [217.235.76.234]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Martin Pitt (ThinkPad)", Issuer "piware CA" (verified OK)) by mail.piware.de (Postfix) with ESMTPS id A9A7B1517A60; Fri, 11 Mar 2011 18:46:42 +0100 (CET) Received: by localhost.localdomain (Postfix, from userid 1000) id 8680B44AE5; Fri, 11 Mar 2011 18:47:10 +0100 (CET) Date: Fri, 11 Mar 2011 18:47:10 +0100 From: Martin Pitt To: PostgreSQL Bugs Cc: Aurelien Jarno , 616180@bugs.debian.org Subject: [patch] test failure on sparc64 due to undefined division by zero behaviour Message-ID: <20110311174710.GF2541@piware.de> Mail-Followup-To: PostgreSQL Bugs , Aurelien Jarno , 616180@bugs.debian.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ffoCPvUAPMgSXi6H" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.107 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RDNS_NONE=0.793 X-Spam-Level: X-Archive-Number: 201103/206 X-Sequence-Number: 29716 --ffoCPvUAPMgSXi6H Content-Type: multipart/mixed; boundary="wULyF7TL5taEdwHz" Content-Disposition: inline --wULyF7TL5taEdwHz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello PostgreSQL hackers, I recently got the following bug report about a test suite failure on sparc64: ----- Forwarded message from Aurelien Jarno ----- Date: Wed, 02 Mar 2011 23:49:05 +0100 =46rom: Aurelien Jarno To: Debian Bug Tracking System Subject: Bug#616180: postgresql-9.0: FTBFS on sparc64, testsuite issues wit= h int8 postgresql-9.0 fails to build on sparc64 due to testsuite errors with=20 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=20 (actually taken in another part from the very same file), so it's=20 probably the best to simply apply it. [1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D29968 ----- 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 --=20 Martin Pitt | http://www.piware.de Ubuntu Developer (www.ubuntu.com) | Debian Developer (www.debian.org) --wULyF7TL5taEdwHz Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Avoid-undefined-division-by-zero.patch" Content-Transfer-Encoding: quoted-printable =46rom 734d86c9482d545f38c9c51e173d7f2287f521bf Mon Sep 17 00:00:00 2001 =46rom: Martin Pitt 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 o= ther 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=3D29968 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; =20 if (arg2 =3D=3D 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(); + } =20 result =3D arg1 / arg2; =20 @@ -813,9 +817,13 @@ int84div(PG_FUNCTION_ARGS) int64 result; =20 if (arg2 =3D=3D 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(); + } =20 result =3D arg1 / arg2; =20 @@ -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(); } =20 @@ -997,9 +1005,13 @@ int82div(PG_FUNCTION_ARGS) int64 result; =20 if (arg2 =3D=3D 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(); + } =20 result =3D arg1 / arg2; =20 @@ -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(); } =20 --=20 1.7.4.1 --wULyF7TL5taEdwHz-- --ffoCPvUAPMgSXi6H Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBCAAGBQJNemAeAAoJEPmIJawmtHufYkkP/2kbjLDgD2hanwCLQ2xsk33r 50/FGk9cDGy5JFGpxGfb/nLnxtUQFyqQsZY3xRtEy0KzKUtvAT7ehuj0xMEOmG0+ Aqd6tnCaJ9v3heEvKIiT5Gf1X3wpNRV2uvPBQdVRony+MnhPiowYNrrqdVA7TKJG SukfzR/Ck3vfcwXDXDbPCJKGgtg5/j8J37YuTSBCeVn/tQ5S01hN+dNnPm6E3+NM wK4ZactSp8Voos1zu2XOKL+vnFqg6xa59TTvvMvhjbAwEiJbHmzzXM2XSXjI8uzS qfxHnu/0TsUd2b4xY+iy93Kv7v6KbPAnJUfl5jyEX/ggKgMN21wyEXe7fGAk/vn7 4tg6Bp2Bn4dV9C26m99u9E+BHeJQEA4mi7nYzXyThtSdswl1SljVXC9nrgYfch+9 qKyHxCrG8XmOY9xbKZpO42so5sCUUs36uoEqJTT8ioeVNTgpm3vM+cCHWsYZQsQ5 E7lScSgstnnP03y2iEJZUoYYgbxQ0qfCj/itfKq24O3ZwrZWamXGO15zaRLQOUmQ m73ycyBvUYLlBCnJpNUuvLl+f6h2Kva6jTeQJtFkzycMPqlCDDzDEH75rJ4Z+K2x P5yzxyWGDJVc18vicDGo8WwS/mmqvfH/8+oxwM55ad8/rOwHySRTBvquqcpfs/SJ rBPARE6WDqjFg67H+Mqt =ley8 -----END PGP SIGNATURE----- --ffoCPvUAPMgSXi6H--