Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit01783ac

Browse files
committed
Fix yet more problems with incorrectly-constructed zero-length arrays.
Commit716ea62 attempted to fix the problem of building 1-D zero-sizearrays once and for all. But it turns out that contrib/intarray has somecode that doesn't use construct_array() but just builds arrays by hand,so it didn't get the memo. This appears to affect all of subarray(),intset_subtract(), inner_int_union(), inner_int_inter(), andintarray_concat_arrays().Back-patch into v11. In the past we've not back-patched this type ofchange, but since v11 is still in beta it seems all right to includethis fix in it. Besides it's more consistent to make the fix in v11where716ea62 appeared.Report and patch by Alexey Kryuchkov, some cosmetic adjustments by meReport:https://postgr.es/m/153053285112.13258.434620894305716755@wrigleys.postgresql.orgDiscussion:https://postgr.es/m/CAN85JcYphDLYt4CpMDLZjjNVqGDrFJ5eS3YF=wLAhFoDQuBsyg@mail.gmail.com
1 parent6abad00 commit01783ac

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

‎contrib/intarray/_int_tool.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,16 @@ ArrayType *
220220
new_intArrayType(intnum)
221221
{
222222
ArrayType*r;
223-
intnbytes=ARR_OVERHEAD_NONULLS(1)+sizeof(int)*num;
223+
intnbytes;
224+
225+
/* if no elements, return a zero-dimensional array */
226+
if (num <=0)
227+
{
228+
r=construct_empty_array(INT4OID);
229+
returnr;
230+
}
231+
232+
nbytes=ARR_OVERHEAD_NONULLS(1)+sizeof(int)*num;
224233

225234
r= (ArrayType*)palloc0(nbytes);
226235

@@ -237,11 +246,11 @@ new_intArrayType(int num)
237246
ArrayType*
238247
resize_intArrayType(ArrayType*a,intnum)
239248
{
240-
intnbytes=ARR_DATA_OFFSET(a)+sizeof(int)*num;
249+
intnbytes;
241250
inti;
242251

243252
/* if no elements, return a zero-dimensional array */
244-
if (num==0)
253+
if (num<=0)
245254
{
246255
ARR_NDIM(a)=0;
247256
returna;
@@ -250,6 +259,8 @@ resize_intArrayType(ArrayType *a, int num)
250259
if (num==ARRNELEMS(a))
251260
returna;
252261

262+
nbytes=ARR_DATA_OFFSET(a)+sizeof(int)*num;
263+
253264
a= (ArrayType*)repalloc(a,nbytes);
254265

255266
SET_VARSIZE(a,nbytes);

‎contrib/intarray/expected/_int.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,30 @@ SELECT '{-1,3,1}'::int[] & '{1,2}';
151151
{1}
152152
(1 row)
153153

154+
SELECT '{1}'::int[] & '{2}'::int[];
155+
?column?
156+
----------
157+
{}
158+
(1 row)
159+
160+
SELECT array_dims('{1}'::int[] & '{2}'::int[]);
161+
array_dims
162+
------------
163+
164+
(1 row)
165+
166+
SELECT ('{1}'::int[] & '{2}'::int[]) = '{}'::int[];
167+
?column?
168+
----------
169+
t
170+
(1 row)
171+
172+
SELECT ('{}'::int[] & '{}'::int[]) = '{}'::int[];
173+
?column?
174+
----------
175+
t
176+
(1 row)
177+
154178
--test query_int
155179
SELECT '1'::query_int;
156180
query_int

‎contrib/intarray/sql/_int.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ SELECT '{123,623,445}'::int[] | 1623;
3030
SELECT'{123,623,445}'::int[] |'{1623,623}';
3131
SELECT'{123,623,445}'::int[] &'{1623,623}';
3232
SELECT'{-1,3,1}'::int[] &'{1,2}';
33+
SELECT'{1}'::int[] &'{2}'::int[];
34+
SELECT array_dims('{1}'::int[] &'{2}'::int[]);
35+
SELECT ('{1}'::int[] &'{2}'::int[])='{}'::int[];
36+
SELECT ('{}'::int[] &'{}'::int[])='{}'::int[];
3337

3438

3539
--test query_int

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp