This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Avoid "unused sp" if EXTEND is the last mentioning sp.
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 20 May 2014 11:44:06 +0000 (07:44 -0400)
committerSteffen Mueller <smueller@cpan.org>
Wed, 28 May 2014 10:34:06 +0000 (12:34 +0200)
Add PERL_UNUSED_VAR(sp) in case the EXTEND (or MEXTEND)
is the last thing mentioning the sp.

Addresses Coverity perl5 CIDs 29199..29201, 29204, 29205, 29206,
29208, 29210, 29212, 29213, 29215, 29216, 29219..29221.

pp.h

diff --git a/pp.h b/pp.h
index 97738c2..09d8bb1 100644 (file)
--- a/pp.h
+++ b/pp.h
@@ -271,23 +271,31 @@ Does not use C<TARG>.  See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>.
 */
 
 #ifdef STRESS_REALLOC
-# define EXTEND(p,n)   (void)(sp = stack_grow(sp,p, (SSize_t)(n)))
+# define EXTEND(p,n)   STMT_START {                                     \
+                           sp = stack_grow(sp,p,(SSize_t) (n));         \
+                           PERL_UNUSED_VAR(sp);                         \
+                       } } STMT_END
 /* Same thing, but update mark register too. */
-# define MEXTEND(p,n)  STMT_START {                                    \
-                           const int markoff = mark - PL_stack_base;   \
-                           sp = stack_grow(sp,p,(SSize_t) (n));        \
-                           mark = PL_stack_base + markoff;             \
-                       } STMT_END
+# define MEXTEND(p,n)   STMT_START {                                    \
+                            const int markoff = mark - PL_stack_base;   \
+                            sp = stack_grow(sp,p,(SSize_t) (n)));       \
+                            mark = PL_stack_base + markoff;             \
+                            PERL_UNUSED_VAR(sp);                        \
+                        } STMT_END
 #else
-# define EXTEND(p,n)   (void)(UNLIKELY(PL_stack_max - p < (SSize_t)(n)) &&     \
-                           (sp = stack_grow(sp,p, (SSize_t) (n))))
-
+# define EXTEND(p,n)   STMT_START {                                     \
+                         if (UNLIKELY(PL_stack_max - p < (int)(n))) {   \
+                           sp = stack_grow(sp,p,(SSize_t) (n));         \
+                           PERL_UNUSED_VAR(sp);                         \
+                         } } STMT_END
 /* Same thing, but update mark register too. */
-# define MEXTEND(p,n)  STMT_START {if (UNLIKELY(PL_stack_max - p < (int)(n))) {\
-                           const int markoff = mark - PL_stack_base;           \
-                           sp = stack_grow(sp,p,(SSize_t) (n));                \
-                           mark = PL_stack_base + markoff;                     \
-                       } } STMT_END
+# define MEXTEND(p,n)  STMT_START {                                     \
+                         if (UNLIKELY(PL_stack_max - p < (int)(n))) {   \
+                           const int markoff = mark - PL_stack_base;    \
+                           sp = stack_grow(sp,p,(SSize_t) (n));         \
+                           mark = PL_stack_base + markoff;              \
+                           PERL_UNUSED_VAR(sp);                         \
+                         } } STMT_END
 #endif
 
 #define PUSHs(s)       (*++sp = (s))