diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2011-08-17 12:03:26 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2011-08-17 12:03:26 -0400 |
commit | 22a55b3af687806e6b3a08a131d00541774eaade (patch) | |
tree | 15043c404bbf24f2d04e297564c0a124a1bafdbd | |
parent | dfee7d16ad2060e9f73f3002fd979acc085f9391 (diff) | |
download | postgresql-22a55b3af687806e6b3a08a131d00541774eaade.tar.gz postgresql-22a55b3af687806e6b3a08a131d00541774eaade.zip |
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
-rw-r--r-- | src/pl/plperl/plperl.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 61252308cd8..5d25695586d 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1077,14 +1077,15 @@ _array_to_datum(AV *av, int *ndims, int *dims, int cur_depth, int i = 0; int len = av_len(av) + 1; - if (len == 0) - astate = accumArrayResult(astate, (Datum) 0, true, atypid, NULL); - for (i = 0; i < len; i++) { + /* fetch the array element */ SV **svp = av_fetch(av, i, FALSE); + + /* see if this element is an array, if so get that */ SV *sav = svp ? get_perl_array_ref(*svp) : NULL; + /* multi-dimensional array? */ if (sav) { AV *nav = (AV *) SvRV(sav); @@ -1148,6 +1149,9 @@ plperl_array_to_datum(SV *src, Oid typid) astate = _array_to_datum((AV *) SvRV(src), &ndims, dims, 1, astate, typid, atypid); + if (!astate) + return PointerGetDatum(construct_empty_array(atypid)); + for (i = 0; i < ndims; i++) lbs[i] = 1; |