[Re: Uncaught exception when dividing integers]
On Tue, Apr 18, 2006 at 10:50:24PM -0400, Bruce Momjian wrote:
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,
--
Martijn van Oosterhout kleptog@svana.org http://svana.org/kleptog/
From each according to his ability. To each according to his ability to
litigate.
? 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
===
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 - 1.65
+++ src/test/regress/regress.c 19 Apr 2006 10:16:59 -
@@ -10,6 +10,12 @@
#include executor/executor.h /* For GetAttributeByName */
#include commands/sequence.h /* for nextval() */
+/* 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);
/*
* Distance from a point to a path
@@ -734,3 +740,33 @@
*--walk = '\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 = 0; /* Avoid compiler constant elimination */
+ volatile float float_val = 0;
+
+ char str[12];
+ sprintf( str, %d, 5/int_val );
+ sprintf( str, %f, 5.0/float_val );
+
+ float_val = -10;
+ sprintf( str, %f, log(float_val) );
+
+ float_val = 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
===
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.out15 Apr 2006 17:45:46 -
1.52
+++ src/test/regress/expected/errors.out19 Apr 2006 10:16:59 -
@@ -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 means
an out-of-range result or an invalid operation, such as division by zero.
-- 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
===
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
- 1.17
+++ src/test/regress/input/create_function_1.source 19 Apr 2006 10:16:59
-
@@ -52,6 +52,11 @@
AS '@abs_builddir@/[EMAIL PROTECTED]@'
LANGUAGE C STRICT;