Change 26781/26830 (SvRTRIM should also write a new '\0' at the end) can cause segfaults
Philippe M. Chiasson [Thu, 26 Jan 2006 13:39:59 +0000 (05:39 -0800)]
From: "Philippe M. Chiasson" <gozer@ActiveState.com>
Message-ID: <43D941AF.1060503@ActiveState.com>
Date: Thu, 26 Jan 2006 13:39:59 -0800

p4raw-id: //depot/perl@26952

mg.c

diff --git a/mg.c b/mg.c
index 1521241..8cfe86d 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -643,10 +643,12 @@ Perl_magic_len(pTHX_ SV *sv, MAGIC *mg)
 #define SvRTRIM(sv) STMT_START { \
     STRLEN len = SvCUR(sv); \
     char * const p = SvPVX(sv); \
-    while (len > 0 && isSPACE(p[len-1])) \
-       --len; \
-    SvCUR_set(sv, len); \
-    p[len] = '\0'; \
+    if (p) { \
+       while (len > 0 && isSPACE(p[len-1])) \
+          --len; \
+       SvCUR_set(sv, len); \
+       p[len] = '\0'; \
+    } \
 } STMT_END
 
 int