]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - util.c
Merge pull request #141 from CurrentResident/big_endian_swap_fix
[xonotic/gmqcc.git] / util.c
diff --git a/util.c b/util.c
index de0c77ff64a7d21ad0c12d41fcf52b2471a30246..030f54fa36e643ab091fbbeb98bb5db1e289df2b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012, 2013
+ * Copyright (C) 2012, 2013, 2014
  *     Dale Weiler
  *     Wolfgang Bumiller
  *
@@ -22,6 +22,7 @@
  * SOFTWARE.
  */
 #define GMQCC_PLATFORM_HEADER
+#include <stdlib.h>
 #include "gmqcc.h"
 #include "platform.h"
 
@@ -110,16 +111,18 @@ void util_endianswap(void *_data, size_t length, unsigned int typesize) {
         switch (typesize) {
             case 1: return;
             case 2:
-                util_swap16((uint16_t*)_data, length>>1);
+                util_swap16((uint16_t*)_data, length);
                 return;
             case 4:
-                util_swap32((uint32_t*)_data, length>>2);
+                util_swap32((uint32_t*)_data, length);
                 return;
             case 8:
-                util_swap64((uint32_t*)_data, length>>3);
+                util_swap64((uint32_t*)_data, length<<1); /* swap64 operates on 32 bit words, thus scale to that length. */
                 return;
 
-            default: exit(EXIT_FAILURE); /* please blow the fuck up! */
+            default:
+                con_err ("util_endianswap: I don't know how to swap a %u byte structure!\n", typesize);
+                exit(EXIT_FAILURE); /* please blow the fuck up! */
         }
 #   endif
 #endif