Hi,

On 2025. 02. 10. 19:56, Anton Moryakov wrote:
---
  archival/dpkg.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/archival/dpkg.c b/archival/dpkg.c
index 8031956e9..ce9aedec7 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -179,8 +179,16 @@ static void make_hash(const char *key, unsigned *start, 
unsigned *decrement, con
                 * shift amount is mod 24 because long int is 32 bit and data
                 * to be shifted is 8, don't want to shift data to where it has
                 * no effect */
-               hash_num += (key[i] + key[i-1]) << ((key[i] * i) % 24);
-       }
+        unsigned long char_sum = (unsigned char)key[i] + (unsigned 
char)key[i-1];
+        unsigned long shift_amount = ((unsigned char)key[i] * i) % 24;
+
+        if (shift_amount >= sizeof(unsigned long) * 8)
+            shift_amount = (sizeof(unsigned long) * 8) - 1;
+
+        unsigned long shifted_value = char_sum << shift_amount;
+
+        hash_num += shifted_value;
+               }
        *start = (unsigned) hash_num % hash_prime;
        *decrement = (unsigned) 1 + (hash_num % (hash_prime - 1));
  }

Why did you break indentation so horribly?

Also, explain to me, how `shift_amount`, a number between 0 and 23, can ever be bigger than `sizeof(unsigned long) * 8`? Are you on a platform where `sizeof(unsigned long)` is less than 3???

Bence

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to