From 52fcc874b74004acc5b33f60333d19094a85be12 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 17:55:36 -0800 Subject: [PATCH] bugfix in memory handling... Rev: src/docode.c:1.27 Rev: src/fsort.c:1.5 Rev: src/global.h:1.15 Rev: src/pike_memory.c:1.8 --- src/docode.c | 16 ++++++++-------- src/fsort.c | 4 ++++ src/global.h | 10 +++------- src/pike_memory.c | 11 +++++++++++ 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/docode.c b/src/docode.c index 53f1650b34..b4163d28ca 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.26 1998/01/29 00:30:33 hubbe Exp $"); +RCSID("$Id: docode.c,v 1.27 1998/01/29 01:55:34 hubbe Exp $"); #include "las.h" #include "program.h" #include "language.h" @@ -764,10 +764,10 @@ static int do_docode2(node *n,int flags) current_switch_values_on_stack=0; current_switch_case=0; current_switch_default=-1; - current_switch_jumptable=(INT32 *)xalloc(sizeof(INT32)*(cases*2+1)); - jumptable=(INT32 *)xalloc(sizeof(INT32)*(cases*2+1)); + current_switch_jumptable=(INT32 *)xalloc(sizeof(INT32)*(cases*2+2)); + jumptable=(INT32 *)xalloc(sizeof(INT32)*(cases*2+2)); - for(e=0; e<cases*2+1; e++) + for(e=1; e<cases*2+2; e++) { jumptable[e]=emit(F_POINTER, 0); current_switch_jumptable[e]=-1; @@ -790,7 +790,7 @@ static int do_docode2(node *n,int flags) { if(order[e] < cases-1) { - int o1=order[e]*2+1; + int o1=order[e]*2+2; if(current_switch_jumptable[o1]==current_switch_jumptable[o1+1] && current_switch_jumptable[o1]==current_switch_jumptable[o1+2]) { @@ -804,16 +804,16 @@ static int do_docode2(node *n,int flags) if(current_switch_default < 0) current_switch_default = ins_label(-1); - for(e=0;e<cases*2+1;e++) + for(e=1;e<cases*2+2;e++) if(current_switch_jumptable[e]==-1) current_switch_jumptable[e]=current_switch_default; order_array(sp[-1].u.array,order); - reorder((void *)(current_switch_jumptable+1),cases,sizeof(INT32)*2,order); + reorder((void *)(current_switch_jumptable+2),cases,sizeof(INT32)*2,order); free((char *)order); - for(e=0; e<cases*2+1; e++) + for(e=1; e<cases*2+2; e++) update_arg(jumptable[e], current_switch_jumptable[e]); update_arg(tmp1, store_constant(sp-1,1)); diff --git a/src/fsort.c b/src/fsort.c index 9c455d8394..fd8cb524ed 100644 --- a/src/fsort.c +++ b/src/fsort.c @@ -80,6 +80,10 @@ 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; diff --git a/src/global.h b/src/global.h index 31b28620a8..0445fa86b2 100644 --- a/src/global.h +++ b/src/global.h @@ -155,18 +155,14 @@ char *alloca (); #define B8_T long #elif SIZEOF_CHAR_P == 8 #define B8_T char * -#elif SIZEOF_DOUBLE == 8 -#define B8_T double #elif defined(B4_T) struct b8_t_s { B4_T x,y; }; -#define B8_T struct b8_t +#define B8_T struct b8_t_s #endif -#if SIZEOF_DOUBLE == 16 -#define B16_T double -#elif defined(B8_T) +#if defined(B8_T) struct b16_t { B8_T x,y; }; -#define B16_T struct b16_t +#define B16_T struct b16_t_s #endif diff --git a/src/pike_memory.c b/src/pike_memory.c index 6838257a33..f6f2c93d99 100644 --- a/src/pike_memory.c +++ b/src/pike_memory.c @@ -44,6 +44,11 @@ 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: \ { \ @@ -92,6 +97,12 @@ void reorder(char *memory, INT32 nitems, INT32 size,INT32 *order) INT32 e; 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) \ -- GitLab