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