develooper Front page | perl.perl5.porters | Postings from January 2010

[perl #72334] Missing update of AvALLOC() in S_sortcv_stacked

Thread Next
From:
Nicholas Clark
Date:
January 25, 2010 00:48
Subject:
[perl #72334] Missing update of AvALLOC() in S_sortcv_stacked
Message ID:
rt-3.6.HEAD-1505-1264372374-917.72334-75-0@perl.org
# New Ticket Created by  Nicholas Clark 
# Please include the string:  [perl #72334]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=72334 >


By code inspection, there is a bug in S_sortcv_stacked(), as it is not
assigning to AvALLOC() if it reallocates @_. I believe that it needs this
patch to fix it:

diff --git a/pp_sort.c b/pp_sort.c
index 12e77f9..0ef567c 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1790,6 +1790,7 @@ S_sortcv_stacked(pTHX_ SV *const a, SV *const b)
 	if (AvMAX(av) < 1) {
 	    AvMAX(av) = 1;
 	    Renew(ary,2,SV*);
+	    AvALLOC(av) = ary;
 	    AvARRAY(av) = ary;
 	}
     }


(compare with the analogous code in pp_ctl.c and pp_hot.c:

			if (items >= AvMAX(av) + 1) {
			    AvMAX(av) = items - 1;
			    Renew(ary,items+1,SV*);
			    AvALLOC(av) = ary;
			    AvARRAY(av) = ary;
			}

)


No tests fail if I made the above change. However, I don't have a test case,
and I don't even know if it's possible to create one.

The bug seems to have existed since the code was added in 1999, originally
in pp_ctl.c: http://perl5.git.perl.org/perl.git/commit/4348140855c01942


Nicholas Clark


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About