From e0bb0da33356b323f852a39312fb6ed6e8b87305 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Wed, 30 Mar 2016 17:20:05 +0200
Subject: [PATCH] Runtime [ia32]: low_hashmem() needs to support small nbytes.

When compiling --with-abi=32 low_hashmem_ia32_crc32() may get called
with an nbytes value of 16 (when hashing the opcode table).

Fixes fatal error in the above case.
---
 src/pike_memory.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/pike_memory.c b/src/pike_memory.c
index 0b1e3cf920..6b62214090 100644
--- a/src/pike_memory.c
+++ b/src/pike_memory.c
@@ -293,9 +293,23 @@ static inline size_t low_hashmem_ia32_crc32( const void *s, size_t len,
     while( len-- )
       CRC32SQ( h, c++ );
     return h;
-  }
-  else
-  {
+  } else if (UNLIKELY(nbytes < 32)) {
+    /* Hash the whole memory area */
+    const unsigned int *e = p + (nbytes>>2);
+    const unsigned char *c = (const unsigned char*)e;
+
+    /* .. all full integers .. */
+    while( p<e ) {
+      CRC32SI(h, p++ );
+    }
+
+    nbytes &= 3;
+
+    /* any remaining bytes. */
+    while( nbytes-- )
+      CRC32SQ( h, c++ );
+    return h;
+  } else {
     const unsigned int *e = p+(nbytes>>2);
 #ifdef PIKE_DEBUG
     /*
-- 
GitLab