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

Commit68dabab

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 parentbfb6686 commit68dabab

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
@@ -1450,17 +1450,25 @@ plperl_ref_from_pg_array(Datum arg, Oid typid)
14501450
info->ndims=ARR_NDIM(ar);
14511451
dims=ARR_DIMS(ar);
14521452

1453-
deconstruct_array(ar,elementtype,typlen,typbyval,
1454-
typalign,&info->elements,&info->nulls,
1455-
&nitems);
1453+
/* No dimensions? Return an empty array */
1454+
if (info->ndims==0)
1455+
{
1456+
av=newRV_noinc((SV*)newAV());
1457+
}
1458+
else
1459+
{
1460+
deconstruct_array(ar,elementtype,typlen,typbyval,
1461+
typalign,&info->elements,&info->nulls,
1462+
&nitems);
14561463

1457-
/* Get total number of elements in each dimension */
1458-
info->nelems=palloc(sizeof(int)*info->ndims);
1459-
info->nelems[0]=nitems;
1460-
for (i=1;i<info->ndims;i++)
1461-
info->nelems[i]=info->nelems[i-1] /dims[i-1];
1464+
/* Get total number of elements in each dimension */
1465+
info->nelems=palloc(sizeof(int)*info->ndims);
1466+
info->nelems[0]=nitems;
1467+
for (i=1;i<info->ndims;i++)
1468+
info->nelems[i]=info->nelems[i-1] /dims[i-1];
14621469

1463-
av=split_array(info,0,nitems,0);
1470+
av=split_array(info,0,nitems,0);
1471+
}
14641472

14651473
hv=newHV();
14661474
(void)hv_store(hv,"array",5,av,0);
@@ -1479,6 +1487,9 @@ split_array(plperl_array_info *info, int first, int last, int nest)
14791487
inti;
14801488
AV*result;
14811489

1490+
/* we should only be called when we have something to split */
1491+
Assert(info->ndims>0);
1492+
14821493
/* since this function recurses, it could be driven to stack overflow */
14831494
check_stack_depth();
14841495

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp