In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/6ec5f825e65b3170c6b870804ad6d5349c9c84d1?hp=395e49858e6cabdc5c8ecc0647e256452bd20f64>

- Log -----------------------------------------------------------------
commit 6ec5f825e65b3170c6b870804ad6d5349c9c84d1
Author: Tony Cook <t...@develop-help.com>
Date:   Wed Jun 11 11:29:55 2014 +1000

    correct handling of buffer sizes for POSIX::strxfrm()
    
    There were two problems:
    
    1) we allocated srclen*4+1, but then only supplied srclen to the first
      strxfrm() call, which meant we could be "failing" the strfrm()
      unnecessarily.
    
    2) the return value of the first strxfrm() was being handled correctly,
      the contents of the output buffer supplied to strxfrm() is indeterminate
      when the return value is the buffer size or larger, so we should
      make a new call then.
-----------------------------------------------------------------------

Summary of changes:
 ext/POSIX/POSIX.xs | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index 9631c7d..0ca1373 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -1596,11 +1596,13 @@ strxfrm(src)
        {
           STRLEN srclen;
           STRLEN dstlen;
+          STRLEN buflen;
           char *p = SvPV(src,srclen);
           srclen++;
-          ST(0) = sv_2mortal(newSV(srclen*4+1));
-          dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)srclen);
-          if (dstlen > srclen) {
+          buflen = srclen * 4 + 1;
+          ST(0) = sv_2mortal(newSV(buflen));
+          dstlen = strxfrm(SvPVX(ST(0)), p, (size_t)buflen);
+          if (dstlen >= buflen) {
               dstlen++;
               SvGROW(ST(0), dstlen);
               strxfrm(SvPVX(ST(0)), p, (size_t)dstlen);

--
Perl5 Master Repository

Reply via email to