diff options
Diffstat (limited to 'contrib/intarray/_int_tool.c')
-rw-r--r-- | contrib/intarray/_int_tool.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c index 2fdfd2ec632..b2ca0573f26 100644 --- a/contrib/intarray/_int_tool.c +++ b/contrib/intarray/_int_tool.c @@ -3,6 +3,8 @@ */ #include "postgres.h" +#include <limits.h> + #include "catalog/pg_type.h" #include "_int.h" @@ -277,16 +279,18 @@ copy_intArrayType(ArrayType *a) int internal_size(int *a, int len) { - int i, - size = 0; + int i; + int64 size = 0; for (i = 0; i < len; i += 2) { - if (!i || a[i] != a[i - 1]) /* do not count repeated range */ - size += a[i + 1] - a[i] + 1; + if (!i || a[i] != a[i - 1]) /* do not count repeated range */ + size += (int64)(a[i + 1]) - (int64)(a[i]) + 1; } - return size; + if (size > (int64)INT_MAX || size < (int64)INT_MIN) + return -1; /* overflow */ + return (int) size; } /* unique-ify elements of r in-place ... r must be sorted already */ |