Skip to content

Commit 21bcd3f

Browse files
Place lbound before updating array len product (pgcentralfoundation#2236)
Without this, Postgres decides the array starts at 5 or whatever.
1 parent 0d8e302 commit 21bcd3f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pgrx/src/array/flat_array.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ where
122122
let mut product = 1 as ffi::c_int;
123123
let mut lbounds = [0 as ffi::c_int; N];
124124
for (&dim, lbound) in dim_lens.iter().zip(lbounds.iter_mut()) {
125+
// current lower bound is last product
126+
*lbound = product;
125127
// We handle the multiplication as usize, then use try_from to fit it down,
126128
// to avoid a risk of an unguarded overflow happening from casts
127129
product = if let Some(val) = dim.checked_mul(product as usize)
@@ -131,7 +133,6 @@ where
131133
} else {
132134
return Err(ArrayAllocError::TooManyElems);
133135
};
134-
*lbound = product;
135136
}
136137
let nelems = product as usize;
137138
if nelems > MAX_ARRAY_SIZE {

0 commit comments

Comments
 (0)