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