summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-09-09 13:02:40 +0100
committerDavid Mitchell <davem@iabyn.com>2015-10-02 11:18:17 +0100
commit73e8ff0004522621dfb42f01966853b51d5522a6 (patch)
tree1e2b70f790f84ab21c55ecfc85291511408af7ed /handy.h
parent0fa1f7e4e66a455cab6ccf1f9c49f2373c1ced80 (diff)
downloadperl-73e8ff0004522621dfb42f01966853b51d5522a6.tar.gz
fix some 32/64-bit compiler warnings
Some bits of code don't do well on a 32-bit system with 64-bit ints (-Duse64bitint) In particular: _MEM_WRAP_NEEDS_RUNTIME_CHECK: if sizeof(MEM_SIZE) > sizeof(n), then the shift count could be negative S_regmatch: ln and n were two different sizes and signesses, so comparing them warned. Since they were being mis-used as two convenient temporary booleans anyway, just use temporary booleans instead. Perl_sv_vcatpvfn_flags: the test/assertion (IV)elen < 0 was (I think) being used to test for signed/unsigned conversion wrap-around. elen is of type STRLEN which is a pointer-based type, so can be 32-bit while IV is 64-bit. Instead compare it to half the maximum value of a STRLEN var to see if it may have wrapped.
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/handy.h b/handy.h
index 031850492c..ffb8e2fc3d 100644
--- a/handy.h
+++ b/handy.h
@@ -1917,10 +1917,13 @@ PoisonWith(0xEF) for catching access to freed memory.
* As well as avoiding the need for a run-time check in some cases, it's
* designed to avoid compiler warnings like:
* comparison is always false due to limited range of data type
+ * It's mathematically equivalent to
+ * max(n) * sizeof(t) > MEM_SIZE_MAX
*/
# define _MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) \
- (sizeof(t) > ((MEM_SIZE)1 << 8*(sizeof(MEM_SIZE) - sizeof(n))))
+ ( sizeof(MEM_SIZE) < sizeof(n) \
+ || sizeof(t) > ((MEM_SIZE)1 << 8*(sizeof(MEM_SIZE) - sizeof(n))))
/* This is written in a slightly odd way to avoid various spurious
* compiler warnings. We *want* to write the expression as