MCPcopy Create free account
hub / github.com/apache/cloudberry / ArrayGetNItems

Function ArrayGetNItems

src/backend/utils/adt/arrayutils.c:71–107  ·  view source on GitHub ↗

* Convert array dimensions into number of elements * * This must do overflow checking, since it is used to validate that a user * dimensionality request doesn't overflow what we can handle. * * The multiplication overflow check only works on machines that have int64 * arithmetic, but that is nearly all platforms these days, and doing check * divides for those that don't seems way too expens

Source from the content-addressed store, hash-verified

69 * divides for those that don't seems way too expensive.
70 */
71int
72ArrayGetNItems(int ndim, const int *dims)
73{
74 int32 ret;
75 int i;
76
77 if (ndim <= 0)
78 return 0;
79 ret = 1;
80 for (i = 0; i < ndim; i++)
81 {
82 int64 prod;
83
84 /* A negative dimension implies that UB-LB overflowed ... */
85 if (dims[i] < 0)
86 ereport(ERROR,
87 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
88 errmsg("array size exceeds the maximum allowed (%d)",
89 (int) MaxArraySize)));
90
91 prod = (int64) ret * (int64) dims[i];
92
93 ret = (int32) prod;
94 if ((int64) ret != prod)
95 ereport(ERROR,
96 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
97 errmsg("array size exceeds the maximum allowed (%d)",
98 (int) MaxArraySize)));
99 }
100 Assert(ret >= 0);
101 if ((Size) ret > MaxArraySize)
102 ereport(ERROR,
103 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
104 errmsg("array size exceeds the maximum allowed (%d)",
105 (int) MaxArraySize)));
106 return (int) ret;
107}
108
109/*
110 * Verify sanity of proposed lower-bound values for an array

Callers 15

sanity_check_tid_arrayFunction · 0.85
ArrayGetNMethod · 0.85
get_text_array_contentsFunction · 0.85
array_iteratorFunction · 0.85
_lt_q_regexFunction · 0.85
_lcaFunction · 0.85
_ltree_compressFunction · 0.85
_arrq_consFunction · 0.85
lt_q_regexFunction · 0.85
arrq_consFunction · 0.85
array_to_jsonb_internalFunction · 0.85
EA_get_flat_sizeFunction · 0.85

Calls 2

errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by 2

predicate_classifyFunction · 0.68
clause_is_strict_forFunction · 0.68