changeset 2706:0511feaf0ec2

fix for LSB
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 06 Jul 2018 16:48:48 +0200
parents 5c18a22cb981
children 38a3054b22ff
files Core/Endianness.h
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Endianness.h	Fri Jul 06 16:33:03 2018 +0200
+++ b/Core/Endianness.h	Fri Jul 06 16:48:48 2018 +0200
@@ -145,7 +145,13 @@
 
 static inline uint16_t __orthanc_bswap16(uint16_t a)
 {
-  return (a << 8) | (a >> 8);
+  const uint8_t* p = reinterpret_cast<const uint8_t*>(&a);
+  return (static_cast<uint32_t>(p[0]) << 8 |
+          static_cast<uint32_t>(p[1]));
+
+  // WARNING: The implementation below makes LSB (Linux Standard
+  // Base) segfault in release builds. Don't use it!!!
+  // return (a << 8) | (a >> 8);
 }
 
 static inline uint32_t __orthanc_bswap32(uint32_t a)