This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PERL_STRLEN_ROUNDUP: parenthesize macro parameter
authorLukas Mai <l.mai@web.de>
Wed, 8 Nov 2017 10:45:05 +0000 (11:45 +0100)
committerLukas Mai <l.mai@web.de>
Wed, 8 Nov 2017 10:45:05 +0000 (11:45 +0100)
Also:
- factor out common expression
- remove redundant double parens
- add spaces to expression

handy.h

diff --git a/handy.h b/handy.h
index f9b9d5a..5347799 100644 (file)
--- a/handy.h
+++ b/handy.h
@@ -2296,6 +2296,7 @@ PoisonWith(0xEF) for catching access to freed memory.
 
 #define MEM_SIZE_MAX ((MEM_SIZE)~0)
 
+#define _PERL_STRLEN_ROUNDUP_UNCHECKED(n) (((n) - 1 + PERL_STRLEN_ROUNDUP_QUANTUM) & ~((MEM_SIZE)PERL_STRLEN_ROUNDUP_QUANTUM - 1))
 
 #ifdef PERL_MALLOC_WRAP
 
@@ -2343,7 +2344,7 @@ PoisonWith(0xEF) for catching access to freed memory.
 
 #define MEM_WRAP_CHECK_(n,t) MEM_WRAP_CHECK(n,t),
 
-#define PERL_STRLEN_ROUNDUP(n) ((void)(((n) > MEM_SIZE_MAX - 2 * PERL_STRLEN_ROUNDUP_QUANTUM) ? (croak_memory_wrap(),0):0),((n-1+PERL_STRLEN_ROUNDUP_QUANTUM)&~((MEM_SIZE)PERL_STRLEN_ROUNDUP_QUANTUM-1)))
+#define PERL_STRLEN_ROUNDUP(n) ((void)(((n) > MEM_SIZE_MAX - 2 * PERL_STRLEN_ROUNDUP_QUANTUM) ? (croak_memory_wrap(),0) : 0), _PERL_STRLEN_ROUNDUP_UNCHECKED(n))
 #else
 
 #define MEM_WRAP_CHECK(n,t)
@@ -2351,7 +2352,7 @@ PoisonWith(0xEF) for catching access to freed memory.
 #define MEM_WRAP_CHECK_2(n,t,a,b)
 #define MEM_WRAP_CHECK_(n,t)
 
-#define PERL_STRLEN_ROUNDUP(n) (((n-1+PERL_STRLEN_ROUNDUP_QUANTUM)&~((MEM_SIZE)PERL_STRLEN_ROUNDUP_QUANTUM-1)))
+#define PERL_STRLEN_ROUNDUP(n) _PERL_STRLEN_ROUNDUP_UNCHECKED(n)
 
 #endif