This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
authorNicholas Clark <nick@ccl4.org>
Fri, 13 Jan 2006 17:56:30 +0000 (17:56 +0000)
committerNicholas Clark <nick@ccl4.org>
Fri, 13 Jan 2006 17:56:30 +0000 (17:56 +0000)
[ 26781]
Gisle notes that SvRTRIM should also write a new '\0' at the end.
p4raw-link: @26781 on //depot/perl: bb4058bb936dbf9d1160c9511e5977b96d967664

p4raw-id: //depot/maint-5.8/perl@26830
p4raw-edited: from //depot/perl@26781 'edit in' mg.c (@26779..)

mg.c

diff --git a/mg.c b/mg.c
index 5a92bcd..896a341 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -574,9 +574,11 @@ Perl_magic_len(pTHX_ SV *sv, MAGIC *mg)
 
 #define SvRTRIM(sv) STMT_START { \
     STRLEN len = SvCUR(sv); \
-    while (len > 0 && isSPACE(SvPVX(sv)[len-1])) \
+    char * const p = SvPVX(sv); \
+    while (len > 0 && isSPACE(p[len-1])) \
        --len; \
     SvCUR_set(sv, len); \
+    p[len] = '\0'; \
 } STMT_END
 
 int