* Verify sanity of proposed lower-bound values for an array * * The lower-bound values must not be so large as to cause overflow when * calculating subscripts, e.g. lower bound 2147483640 with length 10 * must be disallowed. We actually insist that dims[i] + lb[i] be * computable without overflow, meaning that an array with last subscript * equal to INT_MAX will be disallowed. * * It is a
| 119 | * overflowed (negative) dims[] values have been eliminated. |
| 120 | */ |
| 121 | void |
| 122 | ArrayCheckBounds(int ndim, const int *dims, const int *lb) |
| 123 | { |
| 124 | int i; |
| 125 | |
| 126 | for (i = 0; i < ndim; i++) |
| 127 | { |
| 128 | /* PG_USED_FOR_ASSERTS_ONLY prevents variable-isn't-read warnings */ |
| 129 | int32 sum PG_USED_FOR_ASSERTS_ONLY; |
| 130 | |
| 131 | if (pg_add_s32_overflow(dims[i], lb[i], &sum)) |
| 132 | ereport(ERROR, |
| 133 | (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), |
| 134 | errmsg("array lower bound is too large: %d", |
| 135 | lb[i]))); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Compute ranges (sub-array dimensions) for an array slice |
no test coverage detected