Change 29949 by [EMAIL PROTECTED] on 2007/01/24 15:28:38

        Integrate:
        [ 27641]
        Subject: [PATCH] Random accumulated patches
        From: [EMAIL PROTECTED] (Andy Lester)
        Date: Thu, 30 Mar 2006 23:42:28 -0600
        Message-ID: <[EMAIL PROTECTED]>
        
        [somehow the perl.h patch got missed]
        
        [ 27754]
        Subject: [PATCH]es: quiet some warnings (with a free AIX cpp insanity 
avoidance tip)
        From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
        Message-ID: <[EMAIL PROTECTED]>
        Date: Sat, 08 Apr 2006 09:58:43 +0300
        
        [ 27763]
        Subject: [PATCH] Quiet a coverity problem
        From: [EMAIL PROTECTED] (Andy Lester)
        Date: Mon, 10 Apr 2006 23:51:50 -0500
        Message-ID: <[EMAIL PROTECTED]>
        
        [ 27766]
        Stop Perl_newSVpvn_share() potentially leaking the return result from
        bytes_from_utf8().
        
        [ 27769]
        Subject: [PATCH] locale.c: more Safefree() (Coverity finding)
        From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
        Message-Id: <[EMAIL PROTECTED]>
        Date: Tue, 11 Apr 2006 22:08:40 +0300 (EEST)
        
        [ 27770]
        Subject: [PATCH] perlio.c: false Coverity finding (it cannot see that 
two pointers are the same): but help Coverity by removing the temp ptr
        From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
        Message-Id: <[EMAIL PROTECTED]>
        Date: Tue, 11 Apr 2006 23:39:32 +0300 (EEST)
        
        [ 27771]
        Subject: [PATCH] regcomp.c (try II): use &PL_sv_undef for listsv as 
suggested by Nick
        From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
        Message-Id: <[EMAIL PROTECTED]>
        Date: Tue, 11 Apr 2006 23:53:25 +0300 (EEST)
        
        [ 27772]
        Subject: [PATCH] regexec.c: move NULL check earlier to make Coverity 
happier
        From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
        Message-Id: <[EMAIL PROTECTED]>
        Date: Tue, 11 Apr 2006 23:04:48 +0300 (EEST)
        
        [ 27829]
        Subject: [PATCH] Handle null io in leavewrite (not possible?) (Coverity)
        From: [EMAIL PROTECTED]
        Message-ID: <[EMAIL PROTECTED]>
        Date: Sat, 15 Apr 2006 14:13:41 -0400 (EDT)
        
        [ 27836]
        Subject: [PATCH] update to pp_complement() via Coverity
        From: [EMAIL PROTECTED] (Andy Lester)
        Date: Sun, 16 Apr 2006 00:14:23 -0500
        Message-ID: <[EMAIL PROTECTED]>
        
        [ 27837]
        Coverity notes that we might be dereferencing fgv before a check that
        it's not NULL. In fact, the code ordering meant that one "if (fgv)"
        would always be true. So fix this.
        
        [ 27867]
        Add assertions to cover cases where the Coverity scanner thinks we
        could are deferencing a NULL pointer, but we think it missed something
        it should have been capable of figuring out.
        
        [ 27868]
        Note in av_store() that S_regclass relies on being able to pass NULL.

Affected files ...

... //depot/maint-5.8/perl/av.c#40 integrate
... //depot/maint-5.8/perl/hv.c#103 integrate
... //depot/maint-5.8/perl/locale.c#25 integrate
... //depot/maint-5.8/perl/op.c#171 integrate
... //depot/maint-5.8/perl/pad.h#16 integrate
... //depot/maint-5.8/perl/perl.h#135 integrate
... //depot/maint-5.8/perl/perlio.c#87 integrate
... //depot/maint-5.8/perl/pp.c#120 integrate
... //depot/maint-5.8/perl/pp_sys.c#127 integrate
... //depot/maint-5.8/perl/regcomp.c#83 integrate
... //depot/maint-5.8/perl/regexec.c#72 integrate
... //depot/maint-5.8/perl/sv.c#307 integrate

Differences ...

==== //depot/maint-5.8/perl/av.c#40 (text) ====
Index: perl/av.c
--- perl/av.c#39~29807~ 2007-01-14 05:09:22.000000000 -0800
+++ perl/av.c   2007-01-24 07:28:38.000000000 -0800
@@ -277,6 +277,10 @@
 
     if (!av)
        return 0;
+    /* S_regclass relies on being able to pass in a NULL sv
+       (unicode_alternate may be NULL).
+    */
+
     if (!val)
        val = &PL_sv_undef;
 

==== //depot/maint-5.8/perl/hv.c#103 (text) ====
Index: perl/hv.c
--- perl/hv.c#102~29947~        2007-01-24 05:54:09.000000000 -0800
+++ perl/hv.c   2007-01-24 07:28:38.000000000 -0800
@@ -67,6 +67,7 @@
     if (!*root)
        S_more_he(aTHX);
     he = *root;
+    assert(he);
     *root = HeNEXT(he);
     UNLOCK_SV_MUTEX;
     return he;

==== //depot/maint-5.8/perl/locale.c#25 (text) ====
Index: perl/locale.c
--- perl/locale.c#24~29920~     2007-01-22 11:20:43.000000000 -0800
+++ perl/locale.c       2007-01-24 07:28:38.000000000 -0800
@@ -277,6 +277,7 @@
     }
     if (!setlocale_failure) {
 #ifdef USE_LOCALE_CTYPE
+       Safefree(curctype);
        if (! (curctype =
               setlocale(LC_CTYPE,
                         (!done && (lang || PerlEnv_getenv("LC_CTYPE")))
@@ -286,6 +287,7 @@
            curctype = savepv(curctype);
 #endif /* USE_LOCALE_CTYPE */
 #ifdef USE_LOCALE_COLLATE
+       Safefree(curcoll);
        if (! (curcoll =
               setlocale(LC_COLLATE,
                         (!done && (lang || PerlEnv_getenv("LC_COLLATE")))
@@ -295,6 +297,7 @@
            curcoll = savepv(curcoll);
 #endif /* USE_LOCALE_COLLATE */
 #ifdef USE_LOCALE_NUMERIC
+       Safefree(curnum);
        if (! (curnum =
               setlocale(LC_NUMERIC,
                         (!done && (lang || PerlEnv_getenv("LC_NUMERIC")))
@@ -451,12 +454,15 @@
 #endif /* ! LC_ALL */
 
 #ifdef USE_LOCALE_CTYPE
+       Safefree(curctype);
        curctype = savepv(setlocale(LC_CTYPE, NULL));
 #endif /* USE_LOCALE_CTYPE */
 #ifdef USE_LOCALE_COLLATE
+       Safefree(curcoll);
        curcoll = savepv(setlocale(LC_COLLATE, NULL));
 #endif /* USE_LOCALE_COLLATE */
 #ifdef USE_LOCALE_NUMERIC
+       Safefree(curnum);
        curnum = savepv(setlocale(LC_NUMERIC, NULL));
 #endif /* USE_LOCALE_NUMERIC */
     }

==== //depot/maint-5.8/perl/op.c#171 (text) ====
Index: perl/op.c
--- perl/op.c#170~29947~        2007-01-24 05:54:09.000000000 -0800
+++ perl/op.c   2007-01-24 07:28:38.000000000 -0800
@@ -2099,7 +2099,7 @@
 {
     register OP *curop;
     I32 type = o->op_type;
-    SV *sv;
+    SV *sv = NULL;
     int ret = 0;
     I32 oldscope;
     OP *old_next;
@@ -2204,6 +2204,7 @@
        goto nope;
 
     op_free(o);
+    assert(sv);
     if (type == OP_RV2GV)
        return newGVOP(OP_GV, 0, (GV*)sv);
     return newSVOP(OP_CONST, 0, sv);
@@ -3945,7 +3946,9 @@
        cont = append_elem(OP_LINESEQ, cont, unstack);
     }
 
+    assert(block);
     listop = append_list(OP_LINESEQ, (LISTOP*)block, (LISTOP*)cont);
+    assert(listop);
     redo = LINKLIST(listop);
 
     if (expr) {
@@ -6270,6 +6273,7 @@
 
     if (!kid->op_sibling)
        append_elem(OP_SPLIT, o, newSVOP(OP_CONST, 0, newSViv(0)));
+    assert(kid->op_sibling);
 
     kid = kid->op_sibling;
     scalar(kid);

==== //depot/maint-5.8/perl/pad.h#16 (text) ====
Index: perl/pad.h
--- perl/pad.h#15~29906~        2007-01-21 04:16:40.000000000 -0800
+++ perl/pad.h  2007-01-24 07:28:38.000000000 -0800
@@ -141,17 +141,17 @@
            ? AvARRAY((AV*)(AvARRAY(padlist)[1]))[po] : NULL;
     
 
-#define PAD_SET_CUR_NOSAVE(padlist,n) \
-       PL_comppad = (PAD*) (AvARRAY(padlist)[n]);              \
+#define PAD_SET_CUR_NOSAVE(padlist,nth) \
+       PL_comppad = (PAD*) (AvARRAY(padlist)[nth]);            \
        PL_curpad = AvARRAY(PL_comppad);                        \
        DEBUG_Xv(PerlIO_printf(Perl_debug_log,                  \
              "Pad 0x%"UVxf"[0x%"UVxf"] set_cur    depth=%d\n", \
-             PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(n)));
+             PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(nth)));
 
 
-#define PAD_SET_CUR(padlist,n) \
+#define PAD_SET_CUR(padlist,nth) \
        SAVECOMPPAD();                                          \
-       PAD_SET_CUR_NOSAVE(padlist,n);
+       PAD_SET_CUR_NOSAVE(padlist,nth);
 
 
 #define PAD_SAVE_SETNULLPAD()  SAVECOMPPAD(); \

==== //depot/maint-5.8/perl/perl.h#135 (text) ====
Index: perl/perl.h
--- perl/perl.h#134~29929~      2007-01-22 15:29:42.000000000 -0800
+++ perl/perl.h 2007-01-24 07:28:38.000000000 -0800
@@ -5038,7 +5038,7 @@
 #   define Strtoul(s, e, b)    strchr((s), '-') ? ULONG_MAX : (unsigned 
long)strtol((s), (e), (b))
 #endif
 #ifndef Atoul
-#   define Atoul(s)    Strtoul(s, (char **)NULL, 10)
+#   define Atoul(s)    Strtoul(s, NULL, 10)
 #endif
 
 

==== //depot/maint-5.8/perl/perlio.c#87 (text) ====
Index: perl/perlio.c
--- perl/perlio.c#86~29927~     2007-01-22 15:11:29.000000000 -0800
+++ perl/perlio.c       2007-01-24 07:28:38.000000000 -0800
@@ -2801,7 +2801,6 @@
 #endif
                stdio = PerlSIO_fopen(path, mode);
                if (stdio) {
-                   PerlIOStdio *s;
                    if (!f) {
                        f = PerlIO_allocate(aTHX);
                    }
@@ -2809,9 +2808,10 @@
                        mode = PerlIOStdio_mode(mode, tmode);
                    f = PerlIO_push(aTHX_ f, self, mode, PerlIOArg);
                    if (f) {
-                       s = PerlIOSelf(f, PerlIOStdio);
-                       s->stdio = stdio;
-                       PerlIOUnix_refcnt_inc(fileno(s->stdio));
+                       PerlIOSelf(f, PerlIOStdio)->stdio = stdio;
+                       PerlIOUnix_refcnt_inc(fileno(stdio));
+                   } else {
+                       PerlSIO_fclose(stdio);
                    }
                    return f;
                }

==== //depot/maint-5.8/perl/pp.c#120 (text) ====
Index: perl/pp.c
--- perl/pp.c#119~29943~        2007-01-24 04:06:54.000000000 -0800
+++ perl/pp.c   2007-01-24 07:28:38.000000000 -0800
@@ -2451,13 +2451,11 @@
        if (SvUTF8(TARG)) {
          /* Calculate exact length, let's not estimate. */
          STRLEN targlen = 0;
-         U8 *result;
-         U8 *send;
          STRLEN l;
          UV nchar = 0;
          UV nwide = 0;
+         U8 * const send = tmps + len;
 
-         send = tmps + len;
          while (tmps < send) {
            const UV c = utf8n_to_uvchr(tmps, send-tmps, &l, UTF8_ALLOW_ANYUV);
            tmps += UTF8SKIP(tmps);
@@ -2471,30 +2469,37 @@
          tmps -= len;
 
          if (nwide) {
+             U8 *result;
+             U8 *p;
+
              Newxz(result, targlen + 1, U8);
+             p = result;
              while (tmps < send) {
                  const UV c = utf8n_to_uvchr(tmps, send-tmps, &l, 
UTF8_ALLOW_ANYUV);
                  tmps += UTF8SKIP(tmps);
-                 result = uvchr_to_utf8_flags(result, ~c, UNICODE_ALLOW_ANY);
+                 p = uvchr_to_utf8_flags(p, ~c, UNICODE_ALLOW_ANY);
              }
-             *result = '\0';
-             result -= targlen;
+             *p = '\0';
              sv_setpvn(TARG, (char*)result, targlen);
              SvUTF8_on(TARG);
+             Safefree(result);
          }
          else {
+             U8 *result;
+             U8 *p;
+
              Newxz(result, nchar + 1, U8);
+             p = result;
              while (tmps < send) {
                  const U8 c = (U8)utf8n_to_uvchr(tmps, 0, &l, UTF8_ALLOW_ANY);
                  tmps += UTF8SKIP(tmps);
-                 *result++ = ~c;
+                 *p++ = ~c;
              }
-             *result = '\0';
-             result -= nchar;
+             *p = '\0';
              sv_setpvn(TARG, (char*)result, nchar);
              SvUTF8_off(TARG);
+             Safefree(result);
          }
-         Safefree(result);
          SETs(TARG);
          RETURN;
        }
@@ -4155,7 +4160,6 @@
     I32 newlen;
     I32 after;
     I32 diff;
-    SV **tmparyval = NULL;
     const MAGIC * const mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied);
 
     if (mg) {
@@ -4221,6 +4225,7 @@
     }
 
     if (diff < 0) {                            /* shrinking the area */
+       SV **tmparyval;
        if (newlen) {
            Newx(tmparyval, newlen, SV*);       /* so remember insertion */
            Copy(MARK, tmparyval, newlen, SV*);
@@ -4281,15 +4286,14 @@
        }
     }
     else {                                     /* no, expanding (or same) */
+       SV** tmparyval = NULL;
        if (length) {
            Newx(tmparyval, length, SV*);       /* so remember deletion */
            Copy(AvARRAY(ary)+offset, tmparyval, length, SV*);
        }
 
        if (diff > 0) {                         /* expanding */
-
            /* push up or down? */
-
            if (offset < after && diff <= AvARRAY(ary) - AvALLOC(ary)) {
                if (offset) {
                    src = AvARRAY(ary);
@@ -4330,7 +4334,6 @@
                        dst++;
                    }
                }
-               Safefree(tmparyval);
            }
            MARK += length - 1;
        }
@@ -4341,10 +4344,10 @@
                while (length-- > 0)
                    SvREFCNT_dec(tmparyval[length]);
            }
-           Safefree(tmparyval);
        }
        else
            *MARK = &PL_sv_undef;
+       Safefree(tmparyval);
     }
     SP = MARK;
     RETURN;

==== //depot/maint-5.8/perl/pp_sys.c#127 (text) ====
Index: perl/pp_sys.c
--- perl/pp_sys.c#126~29943~    2007-01-24 04:06:54.000000000 -0800
+++ perl/pp_sys.c       2007-01-24 07:28:38.000000000 -0800
@@ -1269,16 +1269,17 @@
     else
        fgv = gv;
 
+    if (!fgv) {
+       DIE(aTHX_ "Not a format reference");
+    }
     cv = GvFORM(fgv);
     if (!cv) {
-       if (fgv) {
-           SV * const tmpsv = sv_newmortal();
-           const char *name;
-           gv_efullname4(tmpsv, fgv, NULL, FALSE);
-           name = SvPV_nolen_const(tmpsv);
-           if (name && *name)
-               DIE(aTHX_ "Undefined format \"%s\" called", name);
-       }
+       SV * const tmpsv = sv_newmortal();
+       const char *name;
+       gv_efullname4(tmpsv, fgv, NULL, FALSE);
+       name = SvPV_nolen_const(tmpsv);
+       if (name && *name)
+           DIE(aTHX_ "Undefined format \"%s\" called", name);
        DIE(aTHX_ "Not a format reference");
     }
     if (CvCLONE(cv))
@@ -1293,16 +1294,18 @@
     dSP;
     GV * const gv = cxstack[cxstack_ix].blk_sub.gv;
     register IO * const io = GvIOp(gv);
-    PerlIO * const ofp = IoOFP(io);
+    PerlIO *ofp;
     PerlIO *fp;
     SV **newsp;
     I32 gimme;
     register PERL_CONTEXT *cx;
 
+    if (!io || !(ofp = IoOFP(io)))
+        goto forget_top;
+
     DEBUG_f(PerlIO_printf(Perl_debug_log, "left=%ld, todo=%ld\n",
          (long)IoLINES_LEFT(io), (long)FmLINES(PL_formtarget)));
-    if (!io || !ofp)
-       goto forget_top;
+
     if (IoLINES_LEFT(io) < FmLINES(PL_formtarget) &&
        PL_formtarget != PL_toptarget)
     {
@@ -5205,7 +5208,6 @@
     }
 
     if (grent) {
-       SV *sv;
        PUSHs(sv_2mortal(newSVpv(grent->gr_name, 0)));
 
 #ifdef GRPASSWD

==== //depot/maint-5.8/perl/regcomp.c#83 (text) ====
Index: perl/regcomp.c
--- perl/regcomp.c#82~29948~    2007-01-24 07:13:14.000000000 -0800
+++ perl/regcomp.c      2007-01-24 07:28:38.000000000 -0800
@@ -3579,8 +3579,10 @@
            ANYOF_FLAGS(ret) |= ANYOF_INVERT;
     }
 
-    if (SIZE_ONLY)
+    if (SIZE_ONLY) {
        RExC_size += ANYOF_SKIP;
+       listsv = &PL_sv_undef; /* For code scanners: listsv always non-NULL. */
+    }
     else {
        RExC_emit += ANYOF_SKIP;
        if (FOLD)

==== //depot/maint-5.8/perl/regexec.c#72 (text) ====
Index: perl/regexec.c
--- perl/regexec.c#71~29948~    2007-01-24 07:13:14.000000000 -0800
+++ perl/regexec.c      2007-01-24 07:28:38.000000000 -0800
@@ -1624,7 +1624,12 @@
     SV* dsv1;
 #endif
     PERL_UNUSED_ARG(data);
-    RX_MATCH_UTF8_set(prog,do_utf8);
+
+    /* Be paranoid... */
+    if (prog == NULL || startpos == NULL) {
+       Perl_croak(aTHX_ "NULL regexp parameter");
+       return 0;
+    }
 
     PL_regcc = 0;
 
@@ -1633,11 +1638,7 @@
     PL_regnarrate = DEBUG_r_TEST;
 #endif
 
-    /* Be paranoid... */
-    if (prog == NULL || startpos == NULL) {
-       Perl_croak(aTHX_ "NULL regexp parameter");
-       return 0;
-    }
+    RX_MATCH_UTF8_set(prog, do_utf8);
 
     multiline = PL_multiline | (prog->reganch & PMf_MULTILINE);
 

==== //depot/maint-5.8/perl/sv.c#307 (text) ====
Index: perl/sv.c
--- perl/sv.c#306~29946~        2007-01-24 05:23:35.000000000 -0800
+++ perl/sv.c   2007-01-24 07:28:38.000000000 -0800
@@ -6443,6 +6443,8 @@
 {
     register SV *sv;
     bool is_utf8 = FALSE;
+    const char *const orig_src = src;
+
     if (len < 0) {
        STRLEN tmplen = -len;
         is_utf8 = TRUE;
@@ -6463,6 +6465,8 @@
     SvPOK_on(sv);
     if (is_utf8)
         SvUTF8_on(sv);
+    if (src != orig_src)
+       Safefree(src);
     return sv;
 }
 
End of Patch.

Reply via email to