f6ea51
From 45908e4d120d33a558a8b052036c56cd0c90b898 Mon Sep 17 00:00:00 2001
f6ea51
From: Yves Orton <demerphq@gmail.com>
f6ea51
Date: Wed, 13 Sep 2017 13:30:25 +0200
f6ea51
Subject: [PATCH] avoid  'the address of ... will always evaluate as ...' warns
f6ea51
 in mem macros
f6ea51
MIME-Version: 1.0
f6ea51
Content-Type: text/plain; charset=UTF-8
f6ea51
Content-Transfer-Encoding: 8bit
f6ea51
f6ea51
In f14cf363205 we added asserts to our memory macros (Copy(), Zero() etc)
f6ea51
to ensure that the target is non-null. These asserts throw warnings like
f6ea51
f6ea51
    perl.c: In function ‘Perl_eval_sv’:
f6ea51
    perl.c:2976:264: warning: the address of ‘myop’ will always evaluate
f6ea51
    as ‘true’ [-Waddress]
f6ea51
         Zero(&myop, 1, UNOP);
f6ea51
f6ea51
which is annoying. This patch changes how these asserts are coded so
f6ea51
we avoid the warning. Thanks to Zefram for the fix.
f6ea51
f6ea51
Signed-off-by: Petr Písař <ppisar@redhat.com>
f6ea51
---
f6ea51
 handy.h | 17 ++++++++++-------
f6ea51
 1 file changed, 10 insertions(+), 7 deletions(-)
f6ea51
f6ea51
diff --git a/handy.h b/handy.h
f6ea51
index 31afaae65e..85e8f70721 100644
f6ea51
--- a/handy.h
f6ea51
+++ b/handy.h
f6ea51
@@ -2409,17 +2409,20 @@ void Perl_mem_log_del_sv(const SV *sv, const char *filename, const int linenumbe
f6ea51
 #define Safefree(d)	safefree(MEM_LOG_FREE((Malloc_t)(d)))
f6ea51
 #endif
f6ea51
 
f6ea51
-#define Move(s,d,n,t)	(MEM_WRAP_CHECK_(n,t) assert(d), assert(s), (void)memmove((char*)(d),(const char*)(s), (n) * sizeof(t)))
f6ea51
-#define Copy(s,d,n,t)	(MEM_WRAP_CHECK_(n,t) assert(d), assert(s), (void)memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)))
f6ea51
-#define Zero(d,n,t)	(MEM_WRAP_CHECK_(n,t) assert(d), (void)memzero((char*)(d), (n) * sizeof(t)))
f6ea51
+#define perl_assert_ptr(p) assert( ((void*)(p)) != 0 )
f6ea51
 
f6ea51
-#define MoveD(s,d,n,t)	(MEM_WRAP_CHECK_(n,t) assert(d), assert(s), memmove((char*)(d),(const char*)(s), (n) * sizeof(t)))
f6ea51
-#define CopyD(s,d,n,t)	(MEM_WRAP_CHECK_(n,t) assert(d), assert(s), memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)))
f6ea51
+
f6ea51
+#define Move(s,d,n,t)	(MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), perl_assert_ptr(s), (void)memmove((char*)(d),(const char*)(s), (n) * sizeof(t)))
f6ea51
+#define Copy(s,d,n,t)	(MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), perl_assert_ptr(s), (void)memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)))
f6ea51
+#define Zero(d,n,t)	(MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), (void)memzero((char*)(d), (n) * sizeof(t)))
f6ea51
+
f6ea51
+#define MoveD(s,d,n,t)	(MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), perl_assert_ptr(s), memmove((char*)(d),(const char*)(s), (n) * sizeof(t)))
f6ea51
+#define CopyD(s,d,n,t)	(MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), perl_assert_ptr(s), memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)))
f6ea51
 #ifdef HAS_MEMSET
f6ea51
-#define ZeroD(d,n,t)	(MEM_WRAP_CHECK_(n,t) assert(d), memzero((char*)(d), (n) * sizeof(t)))
f6ea51
+#define ZeroD(d,n,t)	(MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), memzero((char*)(d), (n) * sizeof(t)))
f6ea51
 #else
f6ea51
 /* Using bzero(), which returns void.  */
f6ea51
-#define ZeroD(d,n,t)	(MEM_WRAP_CHECK_(n,t) assert(d), memzero((char*)(d), (n) * sizeof(t)),d)
f6ea51
+#define ZeroD(d,n,t)	(MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), memzero((char*)(d), (n) * sizeof(t)),d)
f6ea51
 #endif
f6ea51
 
f6ea51
 #define PoisonWith(d,n,t,b)	(MEM_WRAP_CHECK_(n,t) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t)))
f6ea51
-- 
f6ea51
2.13.6
f6ea51