From 50853ddcc3f78cf28b84704abcd686ab865d4089 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 9 Aug 2019 19:24:20 +0100 Subject: [PATCH] winnet.c: improve 64-bit-cleanness in cmpfortree. Commit f2e61275f converted the integer casts in cmpforsearch to uintptr_t from unsigned long. But it left the companion function cmpfortree alone, presumably on the grounds that the compiler didn't report a warning for that one. But those two functions (cmpfortree and cmpforsearch) are used with the same tree234, so they're supposed to implement the same sorting criterion. And the thing they're actually comparing, namely the Windows API typedef SOCKET, is a pointer-sized integer. So there was a latent bug here in which cmpforsearch was comparing all 64 bits of the pointer, while cmpfortree was only comparing the low-order 32. --- windows/winnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/winnet.c b/windows/winnet.c index 535e37b9..14513621 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -124,7 +124,7 @@ static tree234 *sktree; static int cmpfortree(void *av, void *bv) { NetSocket *a = (NetSocket *)av, *b = (NetSocket *)bv; - unsigned long as = (unsigned long) a->s, bs = (unsigned long) b->s; + uintptr_t as = (uintptr_t) a->s, bs = (uintptr_t) b->s; if (as < bs) return -1; if (as > bs)