Skip to contentSkip to conversation

slirp: Fix compiler warning for w64

PATCH In review Stefan Weil 2 participants 2 messages Mar 10, 2012 – Mar 13, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slirp: Fix compiler warning for w64

Casting a pointer to an integer value must use uintptr_t or intptr_t (not long) for portable code. MinGW-w64 requires this because sizeof(long) != sizeof(void *) for w64 hosts, so casting to long raises a compiler warning.

I use uintptr_t instead of intptr_t because changing the sign does not matter here and casting pointers to unsigned values seems more reasonable (the unsigned value is a non negative offset.

---
 slirp/cksum.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
slirp/cksum.c +1 -1
index e43867d..6328660 100644
@@ -75,7 +75,7 @@ int cksum(struct mbuf *m, int len)
 	/*
 	 * Force to even boundary.
 	 */
-	if ((1 & (long) w) && (mlen > 0)) {
+	if ((1 & (uintptr_t)w) && (mlen > 0)) {
 		REDUCE;
 		sum <<= 8;
 		s_util.c[0] = *(uint8_t *)w;
Signature · 1 line
1.7.9
#1 lore raw
Quoted 20 lines · Stefan Weil

Casting a pointer to an integer value must use uintptr_t or intptr_t (not long) for portable code. MinGW-w64 requires this because sizeof(long) != sizeof(void *) for w64 hosts, so casting to long raises a compiler warning.

I use uintptr_t instead of intptr_t because changing the sign does not matter here and casting pointers to unsigned values seems more reasonable (the unsigned value is a non negative offset.

---
 slirp/cksum.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
slirp/cksum.c +0 -0
index e43867d..6328660 100644

slirp/cksum.c int cksum(struct mbuf *m, int len) · line 81

Quoted 8 lines
slirp/cksum.c +1 -1
@@ -75,7 +75,7 @@ int cksum(struct mbuf *m, int len)
 	/*
 	 * Force to even boundary.
 	 */
-	if ((1 & (long) w) && (mlen > 0)) {
+	if ((1 & (uintptr_t)w) && (mlen > 0)) {
 		REDUCE;
 		sum <<= 8;
 		s_util.c[0] = *(uint8_t *)w;

Thanks, I picked this up for the slirp queue for which I will send a pull request later today.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux