fb6d68
From a6636b43dc409e4b49f369c18fedd34332fdb9ab Mon Sep 17 00:00:00 2001
fb6d68
From: Father Chrysostomos <sprout@cpan.org>
fb6d68
Date: Thu, 20 Sep 2012 14:25:38 -0700
fb6d68
Subject: [PATCH] [perl #114984] Glob.xs: Extend stack when returning
fb6d68
fb6d68
If a pattern passed to File::Glob consists of a space-separated list
fb6d68
of patterns, the stack will only be extended by doglob() enough for
fb6d68
the list returned by each subpattern.  So iterate() needs to extend
fb6d68
the stack before copying the list of files from an AV to the stack.
fb6d68
fb6d68
This fixes a regression introduced in 5.16.0.
fb6d68
---
fb6d68
 MANIFEST                   |  1 +
fb6d68
 ext/File-Glob/Glob.xs      |  1 +
fb6d68
 ext/File-Glob/t/rt114984.t | 25 +++++++++++++++++++++++++
fb6d68
 3 files changed, 27 insertions(+)
fb6d68
 create mode 100644 ext/File-Glob/t/rt114984.t
fb6d68
fb6d68
diff --git a/MANIFEST b/MANIFEST
fb6d68
index a7935fc..cceb00e 100644
fb6d68
--- a/MANIFEST
fb6d68
+++ b/MANIFEST
fb6d68
@@ -3748,6 +3748,7 @@ ext/File-Glob/t/basic.t		See if File::Glob works
fb6d68
 ext/File-Glob/t/case.t		See if File::Glob works
fb6d68
 ext/File-Glob/t/global.t	See if File::Glob works
fb6d68
 ext/File-Glob/TODO		File::Glob extension todo list
fb6d68
+ext/File-Glob/t/rt114984.t	See if File::Glob works
fb6d68
 ext/File-Glob/t/taint.t		See if File::Glob works
fb6d68
 ext/GDBM_File/GDBM_File.pm	GDBM extension Perl module
fb6d68
 ext/GDBM_File/GDBM_File.xs	GDBM extension external subroutines
fb6d68
diff --git a/ext/File-Glob/Glob.xs b/ext/File-Glob/Glob.xs
fb6d68
index 3ea0590..d74e7a4 100644
fb6d68
--- a/ext/File-Glob/Glob.xs
fb6d68
+++ b/ext/File-Glob/Glob.xs
fb6d68
@@ -93,6 +93,7 @@ iterate(pTHX_ bool(*globber)(pTHX_ AV *entries, SV *patsv))
fb6d68
     /* chuck it all out, quick or slow */
fb6d68
     if (gimme == G_ARRAY) {
fb6d68
 	if (!on_stack) {
fb6d68
+	    EXTEND(SP, AvFILLp(entries)+1);
fb6d68
 	    Copy(AvARRAY(entries), SP+1, AvFILLp(entries)+1, SV *);
fb6d68
 	    SP += AvFILLp(entries)+1;
fb6d68
 	}
fb6d68
diff --git a/ext/File-Glob/t/rt114984.t b/ext/File-Glob/t/rt114984.t
fb6d68
new file mode 100644
fb6d68
index 0000000..4229c6b
fb6d68
--- /dev/null
fb6d68
+++ b/ext/File-Glob/t/rt114984.t
fb6d68
@@ -0,0 +1,25 @@
fb6d68
+use strict;
fb6d68
+use warnings;
fb6d68
+use v5.16.0;
fb6d68
+use File::Temp 'tempdir';
fb6d68
+use File::Spec::Functions;
fb6d68
+use Test::More tests => 1;
fb6d68
+
fb6d68
+my @md = (1..305);
fb6d68
+my @mp = (1000..1205);
fb6d68
+
fb6d68
+my $path = tempdir uc cleanup => 1;
fb6d68
+
fb6d68
+foreach (@md) {
fb6d68
+    open(my $f, ">", catfile $path, "md_$_.dat");
fb6d68
+    close $f;
fb6d68
+}
fb6d68
+
fb6d68
+foreach (@mp) {
fb6d68
+    open(my $f, ">", catfile $path, "mp_$_.dat");
fb6d68
+    close $f;
fb6d68
+}
fb6d68
+my @b = glob(qq{$path/mp_[0123456789]*.dat
fb6d68
+                $path/md_[0123456789]*.dat});
fb6d68
+is scalar(@b), @md+@mp,
fb6d68
+    'File::Glob extends the stack when returning a long list';
fb6d68
-- 
fb6d68
1.7.11.4
fb6d68