From: Aurelien DARRAGON Date: Wed, 15 Jan 2025 08:43:51 +0000 (+0100) Subject: MINOR: stktable: fix potential build issue in smp_to_stkey (2nd try) X-Git-Tag: v3.2-dev4~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0fb8807820bfaac76dd08f2abeac6bbc9cb67bb1;p=thirdparty%2Fhaproxy.git MINOR: stktable: fix potential build issue in smp_to_stkey (2nd try) As discussed in GH #2838, the previous fix f399dbf ("MINOR: stktable: fix potential build issue in smp_to_stkey") which attempted to remove conversion ambiguity and prevent build warning proved to be insufficient. This time, we implement Willy's suggestion, which is to use an union to perform the conversion. Hopefully this should fix GH #2838. If that's the case (and only in that case), then this patch may be backported with f399dbf (else the patch won't apply) anywhere b59d1fd ("BUG/MINOR: stktable: fix big-endian compatiblity in smp_to_stkey()") was backported. --- diff --git a/src/stick_table.c b/src/stick_table.c index 852995a1a..9dbcadfc7 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -1495,13 +1495,19 @@ struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t) case SMP_T_SINT: { - uint *_sint = (uint *)&smp->data.u.sint; + union { + uint32_t u32; + int64_t s64; + } conv; /* The stick table require a 32bit unsigned int, "sint" is a * signed 64 it, so we can convert it inplace. */ - *_sint = (uint)smp->data.u.sint; - static_table_key.key = _sint; + conv.s64 = 0; + conv.u32 = smp->data.u.sint; + smp->data.u.sint = conv.s64; + + static_table_key.key = &smp->data.u.sint; static_table_key.key_len = 4; break; }