diff options
author | Yves Orton <demerphq@gmail.com> | 2020-01-31 15:34:48 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2020-01-31 15:37:45 +0100 |
commit | 2b301921ff7682e54ab74ad30dbf2ce1c9fc24b1 (patch) | |
tree | be847e310a47167a95628f59deaf59c0d27639e8 /pp_sort.c | |
parent | 3eb35b099f783db0ec40f0ca9f20fd1666c54cdb (diff) | |
download | perl-2b301921ff7682e54ab74ad30dbf2ce1c9fc24b1.tar.gz |
pp_sort.c: fix fencepost error in call to av_extend()
In [rt.cpan.org #39196] issue #17496 there is a report
that Tie::File produced spurious blank lines in the file
after
@tied= sort @tied;
it turns out that this is because Tie::File treats
EXTEND similarly to STORESIZE (which is arguably not
entirely correct, but also not that weird) coupled
with an off by one error in the calls to av_extend()
in pp_sort.
This patch fixes the fencepost error, adds some comments
to av_extend() to make it clear what it is doing, and
adds a test that EXTEND is called by this code with
correct argument.
Diffstat (limited to 'pp_sort.c')
-rw-r--r-- | pp_sort.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -1067,7 +1067,8 @@ PP(pp_sort) for (i = 0; i < max; i++) base[i] = newSVsv(base[i]); av_clear(av); - av_extend(av, max); + if (max) + av_extend(av, max-1); for (i=0; i < max; i++) { SV * const sv = base[i]; SV ** const didstore = av_store(av, i, sv); @@ -1094,7 +1095,7 @@ PP(pp_sort) } av_clear(av); if (max > 0) { - av_extend(av, max); + av_extend(av, max-1); Copy(base, AvARRAY(av), max, SV*); } AvFILLp(av) = max - 1; |