From 506f670114e5fef4ba6c2359df3e77c87e6fbbfb Mon Sep 17 00:00:00 2001 From: Matt Hess Date: Tue, 23 Dec 2025 02:10:13 +0000 Subject: [PATCH] fixed length bug --- src/wallet.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index 368a274..1bb2cb4 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -312,23 +312,22 @@ void Wallet::encode(char (&buf)[ADDRESS_LENGTH]) const // Encode to base58 with variable-length data const int actual_num_full_blocks = static_cast(total_data_size / sizeof(uint64_t)); const int actual_last_block_bytes = static_cast(total_data_size % sizeof(uint64_t)); - const int actual_last_block_size_index = actual_last_block_bytes > 0 ? block_sizes_lookup[actual_last_block_bytes] : -1; - + int buf_index = 0; for (int i = 0; i <= actual_num_full_blocks; ++i) { const bool is_last_block = (i == actual_num_full_blocks); const int bytes_in_block = is_last_block ? actual_last_block_bytes : static_cast(sizeof(uint64_t)); - + if (is_last_block && bytes_in_block == 0) break; - + // Read bytes in big-endian uint64_t n = 0; for (int j = 0; j < bytes_in_block; ++j) { n = (n << 8) | data[i * sizeof(uint64_t) + j]; } - - // Determine output block size - const int output_block_size = is_last_block ? block_sizes[actual_last_block_size_index] : block_sizes.back(); + + // Determine output block size - use block_sizes directly indexed by byte count + const int output_block_size = is_last_block ? block_sizes[actual_last_block_bytes] : block_sizes.back(); // Encode to base58 for (int j = output_block_size - 1; j >= 0; --j) {