summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2018-09-19 15:38:09 -0600
committerKarl Williamson <khw@cpan.org>2018-09-20 08:30:45 -0600
commit30a6480c0da19d85d20a159b9179b5b212c8c768 (patch)
treeeda8cf5fcbc7fcbe656009784d4eb7748306c819
parent86477e8975af27133f77fa918070748d5304ae49 (diff)
downloadperl-30a6480c0da19d85d20a159b9179b5b212c8c768.tar.gz
handy.h: Silence compiler warning
This warning was introduced in db54010671d6c27faf667d658073743b14cd9b58. and is about comparing signed and unsigned results. This commit casts both operands to ptrdiff_t which is likely the widest signed type available on the platform. This can fail if the one of the operands is greater than PTRDIFF_MAX. But lots of other things can fail in that case as well. As the reply from Tomasz Konojacki in the thread starting with http://nntp.perl.org/group/perl.perl5.porters/251541 points out, compilers are now assuming that no object is larger than PTRDIFF_MAX, and if they can assume that, so can we.
-rw-r--r--handy.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/handy.h b/handy.h
index 2ce56ac3a5..325e7fbab4 100644
--- a/handy.h
+++ b/handy.h
@@ -513,16 +513,16 @@ based on the underlying C library functions):
#define strBEGINs(s1,s2) (strncmp(s1,"" s2 "", sizeof(s2)-1) == 0)
#define memBEGINs(s1, l, s2) \
- ( (l) >= sizeof(s2) - 1 \
+ ( (Ptrdiff_t) (l) >= (Ptrdiff_t) sizeof(s2) - 1 \
&& memEQ(s1, "" s2 "", sizeof(s2)-1))
#define memBEGINPs(s1, l, s2) \
- ( (l) > sizeof(s2) - 1 \
+ ( (Ptrdiff_t) (l) > (Ptrdiff_t) sizeof(s2) - 1 \
&& memEQ(s1, "" s2 "", sizeof(s2)-1))
#define memENDs(s1, l, s2) \
- ( (l) >= sizeof(s2) - 1 \
+ ( (Ptrdiff_t) (l) >= (Ptrdiff_t) sizeof(s2) - 1 \
&& memEQ(s1 + (l) - (sizeof(s2) - 1), "" s2 "", sizeof(s2)-1))
#define memENDPs(s1, l, s2) \
- ( (l) > sizeof(s2) \
+ ( (Ptrdiff_t) (l) > (Ptrdiff_t) sizeof(s2) \
&& memEQ(s1 + (l) - (sizeof(s2) - 1), "" s2 "", sizeof(s2)-1))
#endif /* End of making macros private */