Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions regress/expected/expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ NOTICE: graph "expr" has been created

(1 row)

-- Integer division must report bigint overflow instead of raising SIGFPE.
SELECT * FROM cypher('expr', $$
RETURN (-9223372036854775807 - 1) / -1
$$) AS (r agtype);
ERROR: bigint out of range
--
-- map literal
--
Expand Down
5 changes: 5 additions & 0 deletions regress/sql/expr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ SET search_path TO ag_catalog;

SELECT * FROM create_graph('expr');

-- Integer division must report bigint overflow instead of raising SIGFPE.
SELECT * FROM cypher('expr', $$
RETURN (-9223372036854775807 - 1) / -1
$$) AS (r agtype);

--
-- map literal
--
Expand Down
8 changes: 8 additions & 0 deletions src/backend/utils/adt/agtype_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,14 @@ Datum agtype_div(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
}

if (agtv_lhs->val.int_value == PG_INT64_MIN &&
agtv_rhs->val.int_value == -1)
{
ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_NULL();
}

agtv_result.type = AGTV_INTEGER;
agtv_result.val.int_value = agtv_lhs->val.int_value /
agtv_rhs->val.int_value;
Expand Down