Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 22a55b3

Browse files
committed
Properly handle empty arrays returned from plperl functions.
Bug reported by David Wheeler, fix by Alex Hunsaker. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: src/pl/plperl/plperl.c # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # autom4te.cache/ # configure.in~ # doc/src/sgml/ref/grant.sgml~ # src/backend/port/win32_latch.c~ # src/bin/psql/command.c~ # src/include/pg_config.h.win32~ # src/pl/plpython/plpython.c~ # src/tools/msvc/pgbison.bat~ # src/tools/msvc/pgbison.pl.bak # src/tools/msvc/pgflex.bat~ # src/tools/msvc/pgflex.pl.bak # src/tools/pgindent/README~ # src/tools/pgindent/pgindent.pl # src/tools/pgindent/pgindent.pl~ # xxxxx # yyyyyy
1 parent dfee7d1 commit 22a55b3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/pl/plperl/plperl.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,14 +1077,15 @@ _array_to_datum(AV *av, int *ndims, int *dims, int cur_depth,
10771077
int i = 0;
10781078
int len = av_len(av) + 1;
10791079

1080-
if (len == 0)
1081-
astate = accumArrayResult(astate, (Datum) 0, true, atypid, NULL);
1082-
10831080
for (i = 0; i < len; i++)
10841081
{
1082+
/* fetch the array element */
10851083
SV **svp = av_fetch(av, i, FALSE);
1084+
1085+
/* see if this element is an array, if so get that */
10861086
SV *sav = svp ? get_perl_array_ref(*svp) : NULL;
10871087

1088+
/* multi-dimensional array? */
10881089
if (sav)
10891090
{
10901091
AV *nav = (AV *) SvRV(sav);
@@ -1148,6 +1149,9 @@ plperl_array_to_datum(SV *src, Oid typid)
11481149
astate = _array_to_datum((AV *) SvRV(src), &ndims, dims, 1, astate, typid,
11491150
atypid);
11501151

1152+
if (!astate)
1153+
return PointerGetDatum(construct_empty_array(atypid));
1154+
11511155
for (i = 0; i < ndims; i++)
11521156
lbs[i] = 1;
11531157

0 commit comments

Comments
 (0)