diff mbox series

[LIBPHOBOS] Fix ualigned access in murmurhash.d (PR d/89177)

Message ID VI1PR0702MB3840CDBD6452D45826A4910DE4650@VI1PR0702MB3840.eurprd07.prod.outlook.com
State New
Headers show
Series [LIBPHOBOS] Fix ualigned access in murmurhash.d (PR d/89177) | expand

Commit Message

Bernd Edlinger Feb. 12, 2019, 12:08 p.m. UTC
Hi,

in the function MurmurHash3::put an unaligned access fault happens on an arm system.
The linux kernel is able to emulate the unaligned LDM instruction, but it is still not
desirable, to generate code that depends on that.


Fixed by the attached patch.

Bootstrapped and reg-tested on arm-linux-gnueabihf
Is it OK for trunk?


Thanks
Bernd.
diff mbox series

Patch

2019-02-08  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR d/89177
	* src/std/digest/murmurhash.d (MurmurHash3::put): Avoid unaligned
	access traps.

Index: libphobos/src/std/digest/murmurhash.d
===================================================================
--- libphobos/src/std/digest/murmurhash.d	(revision 268614)
+++ libphobos/src/std/digest/murmurhash.d	(working copy)
@@ -516,9 +516,11 @@  struct MurmurHash3(uint size /* 32 or 128 */ , uin
         // Do main work: process chunks of `Element.sizeof` bytes.
         const numElements = data.length / Element.sizeof;
         const remainderStart = numElements * Element.sizeof;
-        foreach (ref const Element block; cast(const(Element[]))(data[0 .. remainderStart]))
+        for (auto start = 0; start < remainderStart; start += Element.sizeof)
         {
-            putElement(block);
+            BufferUnion buffer;
+            buffer.data[0 .. $] = data[start .. start + Element.sizeof];
+            putElement(buffer.block);
         }
         // +1 for bufferLeeway Element.
         element_count += (numElements + 1) * Element.sizeof;