aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/char.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-03-11 21:01:33 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-03-11 21:01:33 +0000
commit31e69ccb210cf49712f77facbf90661d8bc2eed5 (patch)
treeec6e0c1a656051db532cdef53a84309d6180c4a1 /src/backend/utils/adt/char.c
parent6261c75014c9948837d9d025493ef18b8f833f70 (diff)
downloadpostgresql-31e69ccb210cf49712f77facbf90661d8bc2eed5.tar.gz
postgresql-31e69ccb210cf49712f77facbf90661d8bc2eed5.zip
Add explicit tests for division by zero to all user-accessible integer
division and modulo functions, to avoid problems on OS X (which fails to trap 0 divide at all) and Windows (which traps it in some bizarre nonstandard fashion). Standardize on 'division by zero' as the one true spelling of this error message. Add regression tests as suggested by Neil Conway.
Diffstat (limited to 'src/backend/utils/adt/char.c')
-rw-r--r--src/backend/utils/adt/char.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/backend/utils/adt/char.c b/src/backend/utils/adt/char.c
index c31995fdf06..0e2d400aa0d 100644
--- a/src/backend/utils/adt/char.c
+++ b/src/backend/utils/adt/char.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.33 2002/06/20 20:29:36 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.34 2003/03/11 21:01:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -150,6 +150,9 @@ chardiv(PG_FUNCTION_ARGS)
char arg1 = PG_GETARG_CHAR(0);
char arg2 = PG_GETARG_CHAR(1);
+ if (arg2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_CHAR((int8) arg1 / (int8) arg2);
}