diff options
author | Andrew Dunstan | 2011-08-17 15:59:18 +0000 |
---|---|---|
committer | Andrew Dunstan | 2011-08-17 15:59:18 +0000 |
commit | 68c903a66ce6f766a8c99d07034374109859624f (patch) | |
tree | 07c04f1b9a034334c61e37f938e697da35a48ea0 /src | |
parent | 1bf80041e316392b2b602ed5c90904035ca3ac10 (diff) |
Properly handle empty arrays returned from plperl functions.
Bug reported by David Wheeler, fix by Alex Hunsaker.
Diffstat (limited to 'src')
-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 8fd4cfb550b..8b5d4dc1915 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1078,14 +1078,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); @@ -1149,6 +1150,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; |