From 536a98c12f37e6b1afaad2379ada7ab3e3b9af38 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 4 May 2018 18:11:21 +0200 Subject: allowedips: single expression endian choice This will upset millions of curious onlookers, and people will begin to doubt my judgement and sanity. But this really is cleaner to express as a single statement. --- src/allowedips.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/allowedips.c b/src/allowedips.c index c1d9bb8..0f1fed2 100644 --- a/src/allowedips.c +++ b/src/allowedips.c @@ -31,10 +31,7 @@ static __always_inline void swap_endian(u8 *dst, const u8 *src, u8 bits) static void copy_and_assign_cidr(struct allowedips_node *node, const u8 *src, u8 cidr, u8 bits) { node->cidr = cidr; - node->bit_at_a = cidr / 8; -#ifdef __LITTLE_ENDIAN - node->bit_at_a ^= (bits / 8 - 1) % 8; -#endif + node->bit_at_a = (cidr / 8) ^ (((bits / 8 - 1) % 8) * *(u8 *)((u16 []){ 1 })); node->bit_at_b = 7 - (cidr % 8); memcpy(node->bits, src, bits / 8); } -- cgit v1.2.3-59-g8ed1b