--cpvLTH7QU4gwfq3S
Content-Type: multipart/mixed; boundary="ZRyEpB+iJ+qUx0kp"
Content-Disposition: inline
--ZRyEpB+iJ+qUx0kp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
[Re: Uncaught exception when dividing integers]
On Tue, Apr 18, 2006 at 10:50:24PM -0400, Bruce Momjian wrote:
Quote:
=20
Is anyone working on this? |
Not that I know of. However, the first step is to add this regression
test for SIGFPE [-patches CCed]. Note that this will probably redline
windows on the buildfarm. Once this has been added and all
architechures are in compliance, we can deal with the integer overflow
problem.
Triggering a SIGFPE is a bit tricky. On my i386 system the integer
divide will do it, but the rest just return +inf. Given there are
systems that don't SIGFPE the integer divide, I hope one of the others
will trigger... For UNIX systems I've made it try kill() first, that
seems the most reliable.
Have a nice day,
--=20
Martijn van Oosterhout <kleptog (AT) svana (DOT) org> http://svana.org/kleptog/
Quote:
From each according to his ability. To each according to his ability to l=
itigate.
|
--ZRyEpB+iJ+qUx0kp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sigfpe.diff"
Content-Transfer-Encoding: quoted-printable
? src/test/regress/.deps
? src/test/regress/libregress.so.0.0
? src/test/regress/log
? src/test/regress/pg_regress
? src/test/regress/results
? src/test/regress/testtablespace
? src/test/regress/tmp_check
? src/test/regress/expected/constraints.out
? src/test/regress/expected/copy.out
? src/test/regress/expected/create_function_1.out
? src/test/regress/expected/create_function_2.out
? src/test/regress/expected/misc.out
? src/test/regress/expected/tablespace.out
? src/test/regress/sql/constraints.sql
? src/test/regress/sql/copy.sql
? src/test/regress/sql/create_function_1.sql
? src/test/regress/sql/create_function_2.sql
? src/test/regress/sql/misc.sql
? src/test/regress/sql/tablespace.sql
Index: src/test/regress/regress.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D
RCS file: /projects/cvsroot/pgsql/src/test/regress/regress.c,v
retrieving revision 1.65
diff -u -r1.65 regress.c
--- src/test/regress/regress.c 11 Jan 2006 20:12:43 -0000 1.65
+++ src/test/regress/regress.c 19 Apr 2006 10:16:59 -0000
@@ -10,6 +10,12 @@
#include "executor/executor.h" /* For GetAttributeByName */
#include "commands/sequence.h" /* for nextval() */
=20
+/* For the SIGFPE test */
+#if defined(HAVE_POSIX_SIGNALS) && defined (HAVE_UNISTD_H)
+#include <signal.h>
+#include <unistd.h>
+#endif
+
#define P_MAXDIG 12
#define LDELIM '('
#define RDELIM ')'
@@ -26,7 +32,7 @@
extern int oldstyle_length(int n, text *t);
extern Datum int44in(PG_FUNCTION_ARGS);
extern Datum int44out(PG_FUNCTION_ARGS);
-
+extern Datum sigfpe(PG_FUNCTION_ARGS);
=20
/*
* Distance from a point to a path
@@ -734,3 +740,33 @@
*--walk =3D '\0';
PG_RETURN_CSTRING(result);
}
+
+/*
+ * sigfpe - deliberatly generates a floating point exception
+ */
+PG_FUNCTION_INFO_V1(sigfpe);
+
+Datum
+sigfpe(PG_FUNCTION_ARGS)
+{
+#if defined(HAVE_POSIX_SIGNALS) && defined (HAVE_UNISTD_H)
+ /* Most guarenteed way */
+ kill( getpid(), SIGFPE );
+#endif
+ /* If no signals, try to trigger manually */
+ volatile int int_val =3D 0; /* Avoid compiler constant elimination */
+ volatile float float_val =3D 0;
+
+ char str[12];
+ sprintf( str, "%d", 5/int_val );
+ sprintf( str, "%f", 5.0/float_val );
+=09
+ float_val =3D -10;
+ sprintf( str, "%f", log(float_val) );
+
+ float_val =3D 2e+304;
+ sprintf( str, "%1.f", exp10(float_val) );
+ sprintf( str, "%1.f", float_val * float_val );
+
+ PG_RETURN_VOID();
+}
Index: src/test/regress/expected/errors.out
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D
RCS file: /projects/cvsroot/pgsql/src/test/regress/expected/errors.out,v
retrieving revision 1.52
diff -u -r1.52 errors.out
--- src/test/regress/expected/errors.out 15 Apr 2006 17:45:46 -0000 1.52
+++ src/test/regress/expected/errors.out 19 Apr 2006 10:16:59 -0000
@@ -449,6 +449,10 @@
ERROR: syntax error at or near "NUL"
LINE 16: ...L, id2 TEXT NOT NULL PRIMARY KEY, id3 INTEGER NOT NUL, id4 I...
^
+-- Check that floating point exceptions are properly caught
+select sigfpe();
+ERROR: floating-point exception
+DETAIL: An invalid floating-point operation was signaled. This probably m=
eans an out-of-range result or an invalid operation, such as division by ze=
ro.
-- Check that stack depth detection mechanism works and
-- max_stack_depth is not set too high
create function infinite_recurse() returns int as
Index: src/test/regress/input/create_function_1.source
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D
RCS file: /projects/cvsroot/pgsql/src/test/regress/input/create_function_1.=
source,v
retrieving revision 1.17
diff -u -r1.17 create_function_1.source
--- src/test/regress/input/create_function_1.source 27 Feb 2006 16:09:50 -0=
000 1.17
+++ src/test/regress/input/create_function_1.source 19 Apr 2006 10:16:59 -0=
000
@@ -52,6 +52,11 @@
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE C STRICT;
=20
+CREATE FUNCTION sigfpe()=20
+ RETURNS void=20
+ AS '@abs_builddir@/regress@DLSUFFIX@'=20
+ LANGUAGE C STRICT;
+
-- Things that shouldn't work:
=20
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE SQL
Index: src/test/regress/sql/errors.sql
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D
RCS file: /projects/cvsroot/pgsql/src/test/regress/sql/errors.sql,v
retrieving revision 1.13
diff -u -r1.13 errors.sql
--- src/test/regress/sql/errors.sql 11 Feb 2005 22:15:12 -0000 1.13
+++ src/test/regress/sql/errors.sql 19 Apr 2006 10:16:59 -0000
@@ -368,9 +368,13 @@
NOT=20
NULL);
=20
+-- Check that floating point exceptions are properly caught
+select sigfpe();
+
-- Check that stack depth detection mechanism works and
-- max_stack_depth is not set too high
create function infinite_recurse() returns int as
'select infinite_recurse()' language sql;
\set VERBOSITY terse
select infinite_recurse();
+
--ZRyEpB+iJ+qUx0kp--
--cpvLTH7QU4gwfq3S
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFERg7WIB7bNG8LQkwRAilXAJ9R9u0DU1ym0WT5fNesPK 51CSLsiwCfQrIA
knLKON5STu67nUt3EtH5bjo=
=LVNO
-----END PGP SIGNATURE-----
--cpvLTH7QU4gwfq3S--