* workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.56 2002/09/04 20:31:27 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.57 2003/03/11 21:01:33 tgl Exp $
*/
#include "postgres.h"
Cash result;
if (f == 0.0)
- elog(ERROR, "cash_div: divide by 0.0 error");
+ elog(ERROR, "division by zero");
result = rint(c / f);
PG_RETURN_CASH(result);
Cash result;
if (f == 0.0)
- elog(ERROR, "cash_div: divide by 0.0 error");
+ elog(ERROR, "division by zero");
result = rint(c / f);
PG_RETURN_CASH(result);
Cash result;
if (i == 0)
- elog(ERROR, "cash_div_int4: divide by 0 error");
+ elog(ERROR, "division by zero");
result = rint(c / i);
Cash result;
if (s == 0)
- elog(ERROR, "cash_div: divide by 0 error");
+ elog(ERROR, "division by zero");
result = rint(c / s);
PG_RETURN_CASH(result);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.83 2002/11/08 17:37:52 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.84 2003/03/11 21:01:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
double result;
if (arg2 == 0.0)
- elog(ERROR, "float4div: divide by zero error");
+ elog(ERROR, "division by zero");
/* Do division in float8, then check for overflow */
result = (float8) arg1 / (float8) arg2;
float8 result;
if (arg2 == 0.0)
- elog(ERROR, "float8div: divide by zero error");
+ elog(ERROR, "division by zero");
result = arg1 / arg2;
float8 result;
if (arg2 == 0.0)
- elog(ERROR, "float48div: divide by zero");
+ elog(ERROR, "division by zero");
result = arg1 / arg2;
CheckFloat8Val(result);
float8 result;
if (arg2 == 0.0)
- elog(ERROR, "float84div: divide by zero");
+ elog(ERROR, "division by zero");
result = arg1 / arg2;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.74 2003/01/21 19:44:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.75 2003/03/11 21:01:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
div = (p2->x * p2->x) + (p2->y * p2->y);
if (div == 0.0)
- elog(ERROR, "point_div: divide by 0.0 error");
+ elog(ERROR, "division by zero");
result->x = ((p1->x * p2->x) + (p1->y * p2->y)) / div;
result->y = ((p2->x * p1->y) - (p2->y * p1->x)) / div;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.52 2002/08/22 00:01:43 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.53 2003/03/11 21:01:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
+ if (arg2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT32(arg1 / arg2);
}
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
+ if (arg2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT16(arg1 / arg2);
}
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
+ if (arg2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT32(arg1 / arg2);
}
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
+ if (arg2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT32(arg1 / arg2);
}
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
+ if (arg2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT32(arg1 % arg2);
}
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
+ if (arg2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT16(arg1 % arg2);
}
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
+ if (arg2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT32(arg1 % arg2);
}
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
+ if (arg2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT32(arg1 % arg2);
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.42 2002/09/18 21:35:22 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.43 2003/03/11 21:01:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
int64 val1 = PG_GETARG_INT64(0);
int64 val2 = PG_GETARG_INT64(1);
+ if (val2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT64(val1 / val2);
}
int64 val2 = PG_GETARG_INT64(1);
int64 result;
+ if (val2 == 0)
+ elog(ERROR, "division by zero");
+
result = val1 / val2;
result *= val2;
result = val1 - result;
int64 val1 = PG_GETARG_INT64(0);
int32 val2 = PG_GETARG_INT32(1);
+ if (val2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT64(val1 / val2);
}
int32 val1 = PG_GETARG_INT32(0);
int64 val2 = PG_GETARG_INT64(1);
+ if (val2 == 0)
+ elog(ERROR, "division by zero");
+
PG_RETURN_INT64(val1 / val2);
}
*
* 1998 Jan Wieck
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.56 2002/10/19 02:08:17 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.57 2003/03/11 21:01:33 tgl Exp $
*
* ----------
*/
*/
ndigits_tmp = var2->ndigits + 1;
if (ndigits_tmp == 1)
- elog(ERROR, "division by zero on numeric");
+ elog(ERROR, "division by zero");
/*
* Determine the result sign, weight and number of digits to calculate
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.79 2003/02/27 21:36:58 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.80 2003/03/11 21:01:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
result = (Interval *) palloc(sizeof(Interval));
if (factor == 0.0)
- elog(ERROR, "interval_div: divide by 0.0 error");
+ elog(ERROR, "division by zero");
#ifdef HAVE_INT64_TIMESTAMP
result->month = (span->month / factor);
-- notify pg_class
--
--
--- RETRIEVE
+-- SELECT
-- missing relation name
select;
delete from nonesuch;
ERROR: Relation "nonesuch" does not exist
--
--- DESTROY
+-- DROP
-- missing relation name (this had better not wildcard!)
drop table;
drop table nonesuch;
ERROR: table "nonesuch" does not exist
--
--- RENAME
+-- ALTER TABLE
-- relation renaming
-- missing relation name
end;
WARNING: COMMIT: no transaction in progress
--
--- DEFINE AGGREGATE
+-- CREATE AGGREGATE
-- sfunc/finalfunc type disagreement
create aggregate newavg2 (sfunc = int4pl,
basetype = int4,
initcond = '0');
ERROR: Define: "basetype" unspecified
--
--- REMOVE INDEX
+-- DROP INDEX
-- missing index name
drop index;
drop index nonesuch;
ERROR: index "nonesuch" does not exist
--
--- REMOVE AGGREGATE
+-- DROP AGGREGATE
-- missing aggregate name
drop aggregate;
drop aggregate newcnt (float4);
ERROR: RemoveAggregate: aggregate newcnt(real) does not exist
--
--- REMOVE FUNCTION
+-- DROP FUNCTION
-- missing function name
drop function ();
drop function nonesuch();
ERROR: RemoveFunction: function nonesuch() does not exist
--
--- REMOVE TYPE
+-- DROP TYPE
-- missing type name
drop type;
-- no such rule
drop rewrite rule nonesuch;
ERROR: parser: parse error at or near "rewrite" at character 6
+--
+-- Check that division-by-zero is properly caught.
+--
+select 1/0;
+ERROR: division by zero
+select 1::int8/0;
+ERROR: division by zero
+select 1/0::int8;
+ERROR: division by zero
+select 1::int2/0;
+ERROR: division by zero
+select 1/0::int2;
+ERROR: division by zero
+select 1::numeric/0;
+ERROR: division by zero
+select 1/0::numeric;
+ERROR: division by zero
+select 1::float8/0;
+ERROR: division by zero
+select 1/0::float8;
+ERROR: division by zero
+select 1::float4/0;
+ERROR: division by zero
+select 1/0::float4;
+ERROR: division by zero
-- test divide by zero
SELECT '' AS bad, f.f1 / '0.0' from FLOAT4_TBL f;
-ERROR: float4div: divide by zero error
+ERROR: division by zero
SELECT '' AS five, FLOAT4_TBL.*;
five | f1
------+--------------
-- test divide by zero
SELECT '' AS bad, f.f1 / '0.0' from FLOAT4_TBL f;
-ERROR: float4div: divide by zero error
+ERROR: division by zero
SELECT '' AS five, FLOAT4_TBL.*;
five | f1
------+-------------
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
ERROR: exp() result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
-ERROR: float8div: divide by zero error
+ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*;
five | f1
------+-----------------------
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
ERROR: exp() result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
-ERROR: float8div: divide by zero error
+ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*;
five | f1
------+-----------------------
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
ERROR: exp() result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
-ERROR: float8div: divide by zero error
+ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*;
five | f1
------+-----------------------
SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f;
ERROR: exp() result is out of range
SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f;
-ERROR: float8div: divide by zero error
+ERROR: division by zero
SELECT '' AS five, FLOAT8_TBL.*;
five | f1
------+-----------------------
--
--
--- RETRIEVE
+-- SELECT
-- missing relation name
select;
--
--- DESTROY
+-- DROP
-- missing relation name (this had better not wildcard!)
drop table;
--
--- RENAME
+-- ALTER TABLE
-
-- relation renaming
-- missing relation name
--
--- DEFINE AGGREGATE
+-- CREATE AGGREGATE
-- sfunc/finalfunc type disagreement
create aggregate newavg2 (sfunc = int4pl,
--
--- REMOVE INDEX
+-- DROP INDEX
-- missing index name
drop index;
--
--- REMOVE AGGREGATE
+-- DROP AGGREGATE
-- missing aggregate name
drop aggregate;
--
--- REMOVE FUNCTION
+-- DROP FUNCTION
-- missing function name
drop function ();
--
--- REMOVE TYPE
+-- DROP TYPE
-- missing type name
drop type;
-- no such rule
drop rewrite rule nonesuch;
+--
+-- Check that division-by-zero is properly caught.
+--
+
+select 1/0;
+
+select 1::int8/0;
+
+select 1/0::int8;
+
+select 1::int2/0;
+
+select 1/0::int2;
+
+select 1::numeric/0;
+
+select 1/0::numeric;
+
+select 1::float8/0;
+
+select 1/0::float8;
+
+select 1::float4/0;
+
+select 1/0::float4;