From 762b656b53680f64a1d48d8c17d18570ed7b82b1 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 10 Dec 2021 01:12:04 +0000 Subject: [PATCH 1/2] Fix #9740: Fix loading of gamelog change items from savegame ver >= 294 --- src/saveload/gamelog_sl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/saveload/gamelog_sl.cpp b/src/saveload/gamelog_sl.cpp index 89db17424c..72d3f3d852 100644 --- a/src/saveload/gamelog_sl.cpp +++ b/src/saveload/gamelog_sl.cpp @@ -328,6 +328,7 @@ public: size_t length = SlGetStructListLength(UINT32_MAX); la->change = ReallocT(la->change, length); + la->changes = (uint32)length; for (size_t i = 0; i < length; i++) { LoggedChange *lc = &la->change[i]; From bc22e9333e838c73ce27eff6db7a812fab93e638 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 12 Dec 2021 17:35:41 +0100 Subject: [PATCH 2/2] Fix: if vehicles only refit to cargo-slots >= 32, the default cargo was wrong. (#9744) --- src/core/bitmath_func.cpp | 15 ++++++++------- src/core/bitmath_func.hpp | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/core/bitmath_func.cpp b/src/core/bitmath_func.cpp index 803eb9e1ca..206c04e54b 100644 --- a/src/core/bitmath_func.cpp +++ b/src/core/bitmath_func.cpp @@ -24,7 +24,7 @@ const uint8 _ffb_64[64] = { }; /** - * Search the first set bit in a 32 bit variable. + * Search the first set bit in a 64 bit variable. * * This algorithm is a static implementation of a log * congruence search algorithm. It checks the first half @@ -34,7 +34,7 @@ const uint8 _ffb_64[64] = { * @param x The value to search * @return The position of the first bit set */ -uint8 FindFirstBit(uint32 x) +uint8 FindFirstBit(uint64 x) { if (x == 0) return 0; /* The macro FIND_FIRST_BIT is better to use when your x is @@ -42,11 +42,12 @@ uint8 FindFirstBit(uint32 x) uint8 pos = 0; - if ((x & 0x0000ffff) == 0) { x >>= 16; pos += 16; } - if ((x & 0x000000ff) == 0) { x >>= 8; pos += 8; } - if ((x & 0x0000000f) == 0) { x >>= 4; pos += 4; } - if ((x & 0x00000003) == 0) { x >>= 2; pos += 2; } - if ((x & 0x00000001) == 0) { pos += 1; } + if ((x & 0xffffffffULL) == 0) { x >>= 32; pos += 32; } + if ((x & 0x0000ffffULL) == 0) { x >>= 16; pos += 16; } + if ((x & 0x000000ffULL) == 0) { x >>= 8; pos += 8; } + if ((x & 0x0000000fULL) == 0) { x >>= 4; pos += 4; } + if ((x & 0x00000003ULL) == 0) { x >>= 2; pos += 2; } + if ((x & 0x00000001ULL) == 0) { pos += 1; } return pos; } diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp index be0d8cd54d..979d9b73b7 100644 --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -222,7 +222,7 @@ static inline uint8 FindFirstBit2x64(const int value) } } -uint8 FindFirstBit(uint32 x); +uint8 FindFirstBit(uint64 x); uint8 FindLastBit(uint64 x); /**