From 4399515682d4e542c1d05f4e64003f7bac5ba8f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Wed, 28 Jan 1998 18:47:43 -0800
Subject: [PATCH] bugfix for memory handling functions (again)

Rev: src/docode.c:1.28
Rev: src/fsort.c:1.6
Rev: src/pike_memory.c:1.9
---
 src/docode.c      |  4 ++--
 src/fsort.c       |  8 ++++----
 src/pike_memory.c | 27 ++++++++++++++-------------
 3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/src/docode.c b/src/docode.c
index b4163d28ca..47fb435395 100644
--- a/src/docode.c
+++ b/src/docode.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: docode.c,v 1.27 1998/01/29 01:55:34 hubbe Exp $");
+RCSID("$Id: docode.c,v 1.28 1998/01/29 02:47:43 hubbe Exp $");
 #include "las.h"
 #include "program.h"
 #include "language.h"
@@ -762,7 +762,7 @@ static int do_docode2(node *n,int flags)
     emit(F_ALIGN,sizeof(INT32));
 
     current_switch_values_on_stack=0;
-    current_switch_case=0;
+    current_switch_case=1;
     current_switch_default=-1;
     current_switch_jumptable=(INT32 *)xalloc(sizeof(INT32)*(cases*2+2));
     jumptable=(INT32 *)xalloc(sizeof(INT32)*(cases*2+2));
diff --git a/src/fsort.c b/src/fsort.c
index fd8cb524ed..e6439bc84b 100644
--- a/src/fsort.c
+++ b/src/fsort.c
@@ -80,16 +80,16 @@ void fsort(void *base,
 	   long elmSize,
 	   fsortfun cmpfunc)
 {
-#ifdef DEBUG
-  if(((unsigned long)base) % elmSize)
-    fatal("Unaligned memory in argument to fsort()()\n");
-#endif
 
   if(elms<=0) return;
   cmpfun=cmpfunc;
   size=elmSize;
 
+#ifdef HANDLES_UNALIGNED_MEMORY_ACCESS
   switch(elmSize)
+#else
+  switch( (((unsigned long)memory) % elmSize) ? size : 0 )
+#endif
   {
   case  1:  fsort_1(( B1_T *)base,(elms-1)+( B1_T *)base); break;
 #ifdef B2_T
diff --git a/src/pike_memory.c b/src/pike_memory.c
index f6f2c93d99..de2f2f1484 100644
--- a/src/pike_memory.c
+++ b/src/pike_memory.c
@@ -44,10 +44,6 @@ void swap(char *a, char *b, INT32 size)
 
 void reverse(char *memory, INT32 nitems, INT32 size)
 {
-#ifdef DEBUG
-  if(((unsigned long)memory) % size)
-    fatal("Unaligned memory in argument to reverse()\n");
-#endif
 
 #define DOSIZE(X,Y)						\
  case X:							\
@@ -59,7 +55,11 @@ void reverse(char *memory, INT32 nitems, INT32 size)
   break;							\
  }
 
+#ifdef HANDLES_UNALIGNED_MEMORY_ACCESS
   switch(size)
+#else
+  switch( (((unsigned long)memory) % size) ? size : 0 )
+#endif
   {
     DOSIZE(1,B1_T)
 #ifdef B2_T
@@ -98,12 +98,9 @@ void reorder(char *memory, INT32 nitems, INT32 size,INT32 *order)
   char *tmp;
   if(nitems<2) return;
 
-#ifdef DEBUG
-  if(((unsigned long)memory) % size)
-    fatal("Unaligned memory in argument to reorder()\n");
-#endif
 
   tmp=xalloc(size * nitems);
+
 #undef DOSIZE
 #define DOSIZE(X,Y)				\
  case X:					\
@@ -115,17 +112,21 @@ void reorder(char *memory, INT32 nitems, INT32 size,INT32 *order)
  }
   
 
+#ifdef HANDLES_UNALIGNED_MEMORY_ACCESS
   switch(size)
-  {
-    DOSIZE(1,B1_T)
+#else
+  switch( (((unsigned long)memory) % size) ? size : 0 )
+#endif
+ {
+   DOSIZE(1,B1_T)
 #ifdef B2_T
-    DOSIZE(2,B2_T)
+     DOSIZE(2,B2_T)
 #endif
 #ifdef B4_T
-    DOSIZE(4,B4_T)
+     DOSIZE(4,B4_T)
 #endif
 #ifdef B8_T
-    DOSIZE(8,B8_T)
+     DOSIZE(8,B8_T)
 #endif
 #ifdef B16_T
     DOSIZE(16,B16_T)
-- 
GitLab