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

Commit44f9f1f

Browse files
committed
plperl: Correctly handle empty arrays in plperl_ref_from_pg_array.
plperl_ref_from_pg_array() didn't consider the case that postgrs arrayscan have 0 dimensions (when they're empty) and accessed the firstdimension without a check. Fix that by special casing the empty arraycase.Author: Alex HunsakerReported-By: Andres Freund / valgrind / buildfarm animal skinkDiscussion: 20160308063240.usnzg6bsbjrne667@alap3.anarazel.deBackpatch: 9.1-
1 parentb73e816 commit44f9f1f

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

‎src/pl/plperl/plperl.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,17 +1433,25 @@ plperl_ref_from_pg_array(Datum arg, Oid typid)
14331433
info->ndims=ARR_NDIM(ar);
14341434
dims=ARR_DIMS(ar);
14351435

1436-
deconstruct_array(ar,elementtype,typlen,typbyval,
1437-
typalign,&info->elements,&info->nulls,
1438-
&nitems);
1436+
/* No dimensions? Return an empty array */
1437+
if (info->ndims==0)
1438+
{
1439+
av=newRV_noinc((SV*)newAV());
1440+
}
1441+
else
1442+
{
1443+
deconstruct_array(ar,elementtype,typlen,typbyval,
1444+
typalign,&info->elements,&info->nulls,
1445+
&nitems);
14391446

1440-
/* Get total number of elements in each dimension */
1441-
info->nelems=palloc(sizeof(int)*info->ndims);
1442-
info->nelems[0]=nitems;
1443-
for (i=1;i<info->ndims;i++)
1444-
info->nelems[i]=info->nelems[i-1] /dims[i-1];
1447+
/* Get total number of elements in each dimension */
1448+
info->nelems=palloc(sizeof(int)*info->ndims);
1449+
info->nelems[0]=nitems;
1450+
for (i=1;i<info->ndims;i++)
1451+
info->nelems[i]=info->nelems[i-1] /dims[i-1];
14451452

1446-
av=split_array(info,0,nitems,0);
1453+
av=split_array(info,0,nitems,0);
1454+
}
14471455

14481456
hv=newHV();
14491457
(void)hv_store(hv,"array",5,av,0);
@@ -1462,6 +1470,9 @@ split_array(plperl_array_info *info, int first, int last, int nest)
14621470
inti;
14631471
AV*result;
14641472

1473+
/* we should only be called when we have something to split */
1474+
Assert(info->ndims>0);
1475+
14651476
/* since this function recurses, it could be driven to stack overflow */
14661477
check_stack_depth();
14671478

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp