From: Holger Schemel Date: Sun, 21 Nov 2021 23:13:01 +0000 (+0100) Subject: fixed bug with undefined behaviour when shifting left by 32 or more X-Git-Tag: 4.3.1.0~21 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=5bed0c59a91d32e2e82def3a95625b26bb8610a4;p=rocksndiamonds.git fixed bug with undefined behaviour when shifting left by 32 or more The C99 standard says that the result of shifting a number by the width in bits (or more) of the operand is undefined. For intel processors, the shift count is masked to five bits (masked with 31), so trying to left shift a 32-bit value for 32 bits or more does not result in zero, as it might be expected (at least not on intel CPUs). --- diff --git a/src/files.c b/src/files.c index a0e77bcc..d78432d1 100644 --- a/src/files.c +++ b/src/files.c @@ -2814,8 +2814,9 @@ static int LoadLevel_CUS3(File *file, int chunk_size, struct LevelInfo *level) for (x = 0; x < 3; x++) ei->content.e[x][y] = getMappedElement(getFile16BitBE(file)); + // bits 0 - 31 of "has_event[]" event_bits = getFile32BitBE(file); - for (j = 0; j < NUM_CHANGE_EVENTS; j++) + for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++) if (event_bits & (1 << j)) ei->change->has_event[j] = TRUE;