applied patch, with tweak suggested by Michael Parker
[p5sagit/p5-mst-13.2.git] / sv.c
diff --git a/sv.c b/sv.c
index 86e7f50..3652b9d 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -1118,7 +1118,7 @@ sv_grow(SV* sv, unsigned long newlen)
        s = SvPVX(sv);
     if (newlen > SvLEN(sv)) {          /* need more room? */
        if (SvLEN(sv) && s) {
-#if defined(MYMALLOC) && !defined(PURIFY)
+#if defined(MYMALLOC) && !defined(PURIFY) && !defined(LEAKTEST)
            STRLEN l = malloced_size((void*)SvPVX(sv));
            if (newlen <= l) {
                SvLEN_set(sv, l);
@@ -1165,7 +1165,7 @@ sv_setiv(register SV *sv, IV i)
        {
            dTHR;
            croak("Can't coerce %s to integer in %s", sv_reftype(sv,0),
-                 op_desc[op->op_type]);
+                 op_desc[PL_op->op_type]);
        }
     }
     (void)SvIOK_only(sv);                      /* validate number */
@@ -1225,7 +1225,7 @@ sv_setnv(register SV *sv, double num)
        {
            dTHR;
            croak("Can't coerce %s to number in %s", sv_reftype(sv,0),
-                 op_name[op->op_type]);
+                 op_name[PL_op->op_type]);
        }
     }
     SvNVX(sv) = num;
@@ -1288,9 +1288,9 @@ not_a_number(SV *sv)
     }
     *d = '\0';
 
-    if (op)
+    if (PL_op)
        warn("Argument \"%s\" isn't numeric in %s", tmpbuf,
-               op_name[op->op_type]);
+               op_name[PL_op->op_type]);
     else
        warn("Argument \"%s\" isn't numeric", tmpbuf);
 }
@@ -2040,9 +2040,9 @@ sv_setsv(SV *dstr, register SV *sstr)
     case SVt_PVHV:
     case SVt_PVCV:
     case SVt_PVIO:
-       if (op)
+       if (PL_op)
            croak("Bizarre copy of %s in %s", sv_reftype(sstr, 0),
-               op_name[op->op_type]);
+               op_name[PL_op->op_type]);
        else
            croak("Bizarre copy of %s", sv_reftype(sstr, 0));
        break;
@@ -3239,12 +3239,7 @@ sv_gets(register SV *sv, register PerlIO *fp, I32 append)
       /* Grab the size of the record we're getting */
       recsize = SvIV(SvRV(PL_rs));
       (void)SvPOK_only(sv);    /* Validate pointer */
-      /* Make sure we've got the room to yank in the whole thing */
-      if (SvLEN(sv) <= recsize + 3) {
-        /* No, so make it bigger */
-        SvGROW(sv, recsize + 3);
-      }
-      buffer = SvPVX(sv); /* Get the location of the final buffer */
+      buffer = SvGROW(sv, recsize + 1);
       /* Go yank in */
 #ifdef VMS
       /* VMS wants read instead of fread, because fread doesn't respect */
@@ -3255,6 +3250,7 @@ sv_gets(register SV *sv, register PerlIO *fp, I32 append)
       bytesread = PerlIO_read(fp, buffer, recsize);
 #endif
       SvCUR_set(sv, bytesread);
+      buffer[bytesread] = '\0';
       return(SvCUR(sv) ? SvPVX(sv) : Nullch);
     }
     else if (RsPARA(PL_rs)) {
@@ -4042,7 +4038,7 @@ sv_pvn_force(SV *sv, STRLEN *lp)
            else {
                dTHR;
                croak("Can't coerce %s to string in %s", sv_reftype(sv,0),
-                   op_name[op->op_type]);
+                   op_name[PL_op->op_type]);
            }
        }
        else
@@ -4804,10 +4800,10 @@ sv_vcatpvfn(SV *sv, const char *pat, STRLEN patlen, va_list *args, SV **svargs,
        default:
       unknown:
            if (!args && PL_dowarn &&
-                 (op->op_type == OP_PRTF || op->op_type == OP_SPRINTF)) {
+                 (PL_op->op_type == OP_PRTF || PL_op->op_type == OP_SPRINTF)) {
                SV *msg = sv_newmortal();
                sv_setpvf(msg, "Invalid conversion in %s: ",
-                         (op->op_type == OP_PRTF) ? "printf" : "sprintf");
+                         (PL_op->op_type == OP_PRTF) ? "printf" : "sprintf");
                if (c)
                    sv_catpvf(msg, isPRINT(c) ? "\"%%%c\"" : "\"%%\\%03o\"",
                              c & 0xFF);