From 4d8831f2b637bbfe825506f42da72f3668b1eb22 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Mon, 9 Nov 2026 14:31:17 -0300 Subject: [PATCH] unbreak VC98 weird 64-bit handling --- mongoose.c | 6 ++++-- src/ws.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mongoose.c b/mongoose.c index 28a267f6..15209fc8 100644 --- a/mongoose.c +++ b/mongoose.c @@ -30560,9 +30560,11 @@ static size_t mkhdr(size_t len, int op, bool is_client, uint8_t *buf) { } else { uint32_t tmp; buf[1] = 127; - tmp = mg_htonl((uint32_t) (((uint64_t) len) >> 32)); + tmp = (sizeof(len) <= sizeof(uint32_t) || len <= 0xffffffffU) + ? 0 // avoid some 32-bit platforms breaking it (VC98) + : mg_htonl((uint32_t) ((uint64_t) len >> 32)); memcpy(&buf[2], &tmp, sizeof(tmp)); - tmp = mg_htonl((uint32_t) (len & 0xffffffffU)); + tmp = mg_htonl((uint32_t) len); memcpy(&buf[6], &tmp, sizeof(tmp)); n = 10; } diff --git a/src/ws.c b/src/ws.c index 7908f0f0..6e7435b5 100644 --- a/src/ws.c +++ b/src/ws.c @@ -109,9 +109,11 @@ static size_t mkhdr(size_t len, int op, bool is_client, uint8_t *buf) { } else { uint32_t tmp; buf[1] = 127; - tmp = mg_htonl((uint32_t) (((uint64_t) len) >> 32)); + tmp = (sizeof(len) <= sizeof(uint32_t) || len <= 0xffffffffU) + ? 0 // avoid some 32-bit platforms breaking it (VC98) + : mg_htonl((uint32_t) ((uint64_t) len >> 32)); memcpy(&buf[2], &tmp, sizeof(tmp)); - tmp = mg_htonl((uint32_t) (len & 0xffffffffU)); + tmp = mg_htonl((uint32_t) len); memcpy(&buf[6], &tmp, sizeof(tmp)); n = 10; }