Change 29920 by [EMAIL PROTECTED] on 2007/01/22 19:20:43
Integrate:
[ 27668]
If the passed in target rv for Perl_newSVrv() was already a reference
to something, it would leak the reference count on that thing.
[ 27676]
'SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)' is 'SvIV(sv)' so write it as such.
[ 27696]
Take splint into account for PERL_UNUSED_ARG (patch by Jarkko)
[ 27723]
Initializing variables is good. This is another Coverity catch.
[ 27724]
Try not to use negative values when accessing arrays in C. Yet another
Coverity catch.
[ 27726]
Perl_save_alloc can use the new(er) SSGROW rather than looping.
[ 27750]
Subject: Re: [PATCH] locale.c: Coverity finding
From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
Date: Sun, 09 Apr 2006 10:31:32 +0300
Message-ID: <[EMAIL PROTECTED]>
[ 27755]
Subject: [PATCH] pp_sys.c: some Coverity findings: NULL guards for io
pointers
From: [EMAIL PROTECTED] (Jarkko Hietaniemi)
Message-Id: <[EMAIL PROTECTED]>
Date: Sat, 8 Apr 2006 18:52:32 +0300 (EEST)
[ 27757]
Subject: [PATCH] Fix coverity warning in utf8.c
From: Andy Dougherty <[EMAIL PROTECTED]>
Date: Mon, 10 Apr 2006 11:18:35 -0400 (EDT)
Message-ID: <[EMAIL PROTECTED]>
Affected files ...
... //depot/maint-5.8/perl/XSUB.h#34 integrate
... //depot/maint-5.8/perl/locale.c#24 integrate
... //depot/maint-5.8/perl/mg.c#128 integrate
... //depot/maint-5.8/perl/perl.h#132 integrate
... //depot/maint-5.8/perl/pp_sys.c#125 integrate
... //depot/maint-5.8/perl/scope.c#56 integrate
... //depot/maint-5.8/perl/sv.c#301 integrate
... //depot/maint-5.8/perl/utf8.c#66 integrate
... //depot/maint-5.8/perl/util.c#123 integrate
Differences ...
==== //depot/maint-5.8/perl/XSUB.h#34 (text) ====
Index: perl/XSUB.h
--- perl/XSUB.h#33~29903~ 2007-01-20 16:16:12.000000000 -0800
+++ perl/XSUB.h 2007-01-22 11:20:43.000000000 -0800
@@ -83,7 +83,7 @@
*/
#ifndef PERL_UNUSED_ARG
-# ifdef lint
+# if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */
# include <note.h>
# define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x))
# else
@@ -114,7 +114,7 @@
#define dITEMS I32 items = SP - MARK
-#ifdef lint
+#if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */
# define dXSARGS \
NOTE(ARGUNUSED(cv)) \
dSP; dAXMARK; dITEMS
==== //depot/maint-5.8/perl/locale.c#24 (text) ====
Index: perl/locale.c
--- perl/locale.c#23~29897~ 2007-01-20 10:14:46.000000000 -0800
+++ perl/locale.c 2007-01-22 11:20:43.000000000 -0800
@@ -316,18 +316,21 @@
if (!setlocale_failure) {
#ifdef USE_LOCALE_CTYPE
+ Safefree(curctype);
if (! (curctype = setlocale(LC_CTYPE, "")))
setlocale_failure = TRUE;
else
curctype = savepv(curctype);
#endif /* USE_LOCALE_CTYPE */
#ifdef USE_LOCALE_COLLATE
+ Safefree(curcoll);
if (! (curcoll = setlocale(LC_COLLATE, "")))
setlocale_failure = TRUE;
else
curcoll = savepv(curcoll);
#endif /* USE_LOCALE_COLLATE */
#ifdef USE_LOCALE_NUMERIC
+ Safefree(curnum);
if (! (curnum = setlocale(LC_NUMERIC, "")))
setlocale_failure = TRUE;
else
==== //depot/maint-5.8/perl/mg.c#128 (text) ====
Index: perl/mg.c
--- perl/mg.c#127~29915~ 2007-01-22 07:49:59.000000000 -0800
+++ perl/mg.c 2007-01-22 11:20:43.000000000 -0800
@@ -2186,7 +2186,7 @@
sv_setsv(PL_bodytarget, sv);
break;
case '\003': /* ^C */
- PL_minus_c = (bool)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+ PL_minus_c = (bool)SvIV(sv);
break;
case '\004': /* ^D */
@@ -2195,25 +2195,25 @@
PL_debug = get_debug_opts_flags((char **)&s, 0) | DEBUG_TOP_FLAG;
DEBUG_x(dump_all());
#else
- PL_debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | DEBUG_TOP_FLAG;
+ PL_debug = (SvIV(sv)) | DEBUG_TOP_FLAG;
#endif
break;
case '\005': /* ^E */
if (*(mg->mg_ptr+1) == '\0') {
#ifdef MACOS_TRADITIONAL
- gMacPerl_OSErr = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ gMacPerl_OSErr = SvIV(sv);
#else
# ifdef VMS
- set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+ set_vaxc_errno(SvIV(sv));
# else
# ifdef WIN32
SetLastError( SvIV(sv) );
# else
# ifdef OS2
- os2_setsyserrno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+ os2_setsyserrno(SvIV(sv));
# else
/* will anyone ever use this? */
- SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4);
+ SETERRNO(SvIV(sv), 4);
# endif
# endif
# endif
@@ -2231,10 +2231,10 @@
}
break;
case '\006': /* ^F */
- PL_maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ PL_maxsysfd = SvIV(sv);
break;
case '\010': /* ^H */
- PL_hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ PL_hints = SvIV(sv);
break;
case '\011': /* ^I */ /* NOT \t in EBCDIC */
Safefree(PL_inplace);
@@ -2257,7 +2257,7 @@
}
break;
case '\020': /* ^P */
- PL_perldb = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ PL_perldb = SvIV(sv);
if (PL_perldb && !PL_DBsingle)
init_debugger();
break;
@@ -2265,7 +2265,7 @@
#ifdef BIG_TIME
PL_basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv));
#else
- PL_basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+ PL_basetime = (Time_t)SvIV(sv);
#endif
break;
case '\025': /* ^UTF8CACHE */
@@ -2276,7 +2276,7 @@
case '\027': /* ^W & $^WARNING_BITS */
if (*(mg->mg_ptr+1) == '\0') {
if ( ! (PL_dowarn & G_WARN_ALL_MASK)) {
- i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ i = SvIV(sv);
PL_dowarn = (PL_dowarn & ~G_WARN_ON)
| (i ? G_WARN_ON : G_WARN_OFF) ;
}
@@ -2335,22 +2335,22 @@
IoFMT_GV(GvIOp(PL_defoutgv)) = gv_fetchsv(sv, GV_ADD, SVt_PVIO);
break;
case '=':
- IoPAGE_LEN(GvIOp(PL_defoutgv)) = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+ IoPAGE_LEN(GvIOp(PL_defoutgv)) = (SvIV(sv));
break;
case '-':
- IoLINES_LEFT(GvIOp(PL_defoutgv)) = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+ IoLINES_LEFT(GvIOp(PL_defoutgv)) = (SvIV(sv));
if (IoLINES_LEFT(GvIOp(PL_defoutgv)) < 0L)
IoLINES_LEFT(GvIOp(PL_defoutgv)) = 0L;
break;
case '%':
- IoPAGE(GvIOp(PL_defoutgv)) = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+ IoPAGE(GvIOp(PL_defoutgv)) = (SvIV(sv));
break;
case '|':
{
IO * const io = GvIOp(PL_defoutgv);
if(!io)
break;
- if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0)
+ if ((SvIV(sv)) == 0)
IoFLAGS(io) &= ~IOf_FLUSH;
else {
if (!(IoFLAGS(io) & IOf_FLUSH)) {
@@ -2396,7 +2396,7 @@
PL_ofmt = savesvpv(sv);
break;
case '[':
- PL_compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ PL_compiling.cop_arybase = SvIV(sv);
break;
case '?':
#ifdef COMPLEX_STATUS
@@ -2411,7 +2411,7 @@
STATUS_NATIVE_CHILD_SET((U32)SvIV(sv));
else
#endif
- STATUS_UNIX_EXIT_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
+ STATUS_UNIX_EXIT_SET(SvIV(sv));
break;
case '!':
{
@@ -2425,7 +2425,7 @@
}
break;
case '<':
- PL_uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ PL_uid = SvIV(sv);
if (PL_delaymagic) {
PL_delaymagic |= DM_RUID;
break; /* don't do magic till later */
@@ -2457,7 +2457,7 @@
PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
break;
case '>':
- PL_euid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ PL_euid = SvIV(sv);
if (PL_delaymagic) {
PL_delaymagic |= DM_EUID;
break; /* don't do magic till later */
@@ -2484,7 +2484,7 @@
PL_tainting |= (PL_uid && (PL_euid != PL_uid || PL_egid != PL_gid));
break;
case '(':
- PL_gid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ PL_gid = SvIV(sv);
if (PL_delaymagic) {
PL_delaymagic |= DM_RGID;
break; /* don't do magic till later */
@@ -2538,7 +2538,7 @@
Safefree(gary);
}
#else /* HAS_SETGROUPS */
- PL_egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
+ PL_egid = SvIV(sv);
#endif /* HAS_SETGROUPS */
if (PL_delaymagic) {
PL_delaymagic |= DM_EGID;
==== //depot/maint-5.8/perl/perl.h#132 (text) ====
Index: perl/perl.h
--- perl/perl.h#131~29912~ 2007-01-21 15:33:27.000000000 -0800
+++ perl/perl.h 2007-01-22 11:20:43.000000000 -0800
@@ -182,7 +182,7 @@
* but we cannot quite get rid of, such as "ax" in PPCODE+noargs xsubs
*/
#ifndef PERL_UNUSED_ARG
-# ifdef lint
+# if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */
# include <note.h>
# define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x))
# else
==== //depot/maint-5.8/perl/pp_sys.c#125 (text) ====
Index: perl/pp_sys.c
--- perl/pp_sys.c#124~29919~ 2007-01-22 10:47:36.000000000 -0800
+++ perl/pp_sys.c 2007-01-22 11:20:43.000000000 -0800
@@ -2329,7 +2329,7 @@
if (!gv || !io) {
if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
report_evil_fh(gv, io, PL_op->op_type);
- if (IoIFP(io))
+ if (io && IoIFP(io))
do_close(gv, FALSE);
SETERRNO(EBADF,LIB_INVARG);
RETPUSHUNDEF;
@@ -2385,9 +2385,9 @@
if (!gv2 || !io2)
report_evil_fh(gv1, io2, PL_op->op_type);
}
- if (IoIFP(io1))
+ if (io1 && IoIFP(io1))
do_close(gv1, FALSE);
- if (IoIFP(io2))
+ if (io2 && IoIFP(io2))
do_close(gv2, FALSE);
RETPUSHUNDEF;
}
==== //depot/maint-5.8/perl/scope.c#56 (text) ====
Index: perl/scope.c
--- perl/scope.c#55~29904~ 2007-01-20 16:30:14.000000000 -0800
+++ perl/scope.c 2007-01-22 11:20:43.000000000 -0800
@@ -579,9 +579,7 @@
- (char*)PL_savestack);
register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack));
- /* SSCHECK may not be good enough */
- while (PL_savestack_ix + elems + 2 > PL_savestack_max)
- savestack_grow();
+ SSGROW(elems + 2);
PL_savestack_ix += elems;
SSPUSHINT(elems);
==== //depot/maint-5.8/perl/sv.c#301 (text) ====
Index: perl/sv.c
--- perl/sv.c#300~29915~ 2007-01-22 07:49:59.000000000 -0800
+++ perl/sv.c 2007-01-22 11:20:43.000000000 -0800
@@ -7118,9 +7118,11 @@
sv_clear(rv);
SvFLAGS(rv) = 0;
SvREFCNT(rv) = refcnt;
- }
- if (SvTYPE(rv) < SVt_RV)
+ sv_upgrade(rv, SVt_RV);
+ } else if (SvROK(rv)) {
+ SvREFCNT_dec(SvRV(rv));
+ } else if (SvTYPE(rv) < SVt_RV)
sv_upgrade(rv, SVt_RV);
else if (SvTYPE(rv) > SVt_RV) {
SvPV_free(rv);
==== //depot/maint-5.8/perl/utf8.c#66 (text) ====
Index: perl/utf8.c
--- perl/utf8.c#65~29897~ 2007-01-20 10:14:46.000000000 -0800
+++ perl/utf8.c 2007-01-22 11:20:43.000000000 -0800
@@ -283,9 +283,10 @@
c = UTF8SKIP(x);
if (IS_UTF8_CHAR_FAST(c)) {
if (!IS_UTF8_CHAR(x, c))
- goto out;
- } else if (!is_utf8_char_slow(x, c))
- goto out;
+ c = 0;
+ }
+ else
+ c = is_utf8_char_slow(x, c);
#else
c = is_utf8_char(x);
#endif /* #ifdef IS_UTF8_CHAR */
==== //depot/maint-5.8/perl/util.c#123 (text) ====
Index: perl/util.c
--- perl/util.c#122~29897~ 2007-01-20 10:14:46.000000000 -0800
+++ perl/util.c 2007-01-22 11:20:43.000000000 -0800
@@ -3688,6 +3688,7 @@
const char * const func =
op == OP_READLINE ? "readline" : /* "<HANDLE>" not nice */
op == OP_LEAVEWRITE ? "write" : /* "write exit" not nice */
+ op < 0 ? "" : /* handle phoney cases */
PL_op_desc[op];
const char * const pars = OP_IS_FILETEST(op) ? "" : "()";
const char * const type = OP_IS_SOCKET(op)
End of Patch.