gpi-hash.c segfaults

Wed, 30 Jul 1997 16:16:36 +1100



--Message-Boundary-30112
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body

I'VE FIXED IT!!  The problem was caused by a negative index into the 
hash table.  To fix it change the line (gci-hash.c:122):

(((((char *)(NODE))-(char *)0) >> 2) % MAX_HASH_TABLE)

to:

(((((unsigned long)(NODE))-(unsigned long)0) >> 2) % MAX_HASH_TABLE)

(patch attached)

Now for the explanation: when gcc subtracts pointers, a SIGNED 
integer is produced and all further operations on that value used the 
signed versions (eg cwd,idiv to get the modulus). The reason this 
showed up for me and not Peter is djgpp's sbrk algorithm mixed with 
window's memory allocation: sbrk allocates separate dpmi memory 
chunks each time it is called and under windows (3.x or 95), the 
allocated memory can very easily come from BELOW the beginning of the 
program. This will result in pointers in the range 0xfxxxxxxx. As to 
the reproducability: it all depends on the fragmentation of dpmi 
memory under windows (cwsdpmi doesn't seem to have this problem, and 
nor does dosemu I suppose).

Well, anyway, maybe now this bug can be laid to rest...

Bill
--
Leave others their otherness.


--Message-Boundary-30112
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Text from file 'gpi-hash.patch'

*** gpi-hash.c~	Tue Jul 22 14:04:30 1997
--- gpi-hash.c	Wed Jul 30 16:04:00 1997
***************
*** 119,125 ****
  
  
  #define HASH_FUNC(NODE) \
! (((((char *)(NODE))-(char *)0) >> 2) % MAX_HASH_TABLE)
  
  /* return pointer to a node uid field */
  int *
--- 119,125 ----
  
  
  #define HASH_FUNC(NODE) \
! (((((unsigned long)(NODE))-(unsigned long)0) >> 2) % MAX_HASH_TABLE)
  
  /* return pointer to a node uid field */
  int *

--Message-Boundary-30112--


Bill Currie (billc@blackmagic.tait.co.nz)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es