Re: gpi-hash.c segfaults
According to Bill Currie:
I'VE FIXED IT!! The problem was caused by a negative index into the hash table.
Congratulations and thank you!
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)
Since pointers and `long' integers don't have the same size on some sytems (I know it for the Alpha), I think this should be changed to something like `(unsigned size_t)'.
[...] Well, anyway, maybe now this bug can be laid to rest...
I hope so, too. Having this, it's realistic to have the next beta release within the next days ... Yours, Peter Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201] maintainer GNU Pascal [970714] - http://home.pages.de/~gnu-pascal/ [970125]
On Thu, 31 Jul 1997, Peter Gerwinski wrote:
According to Bill Currie:
I'VE FIXED IT!! The problem was caused by a negative index into the hash table.
Congratulations and thank you!
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)
Since pointers and `long' integers don't have the same size on some sytems (I know it for the Alpha), I think this should be changed to something like `(unsigned size_t)'.
Peter, In the alpha: sizeof(long) == sizeof(void *) sizeof(int) != sizeof(void *) Quickly thinking, in all Unix machines it might be that sizeof(long) == sizeof (void *). But this just might not always be the case, so it can not be trusted. In ANSI C the result of (ptr - ptr) is of type ptrdiff_t, which in the alpha is (signed long). Using cast (unsigned size_t) might not be a good idea, at least I do not know if Ansi C quarantees that size_t always is as large as ptrdiff_t. I suggest that this problem is fixed by casting the result of the pointer subtraction to (unsigned ptrdiff_t) which is always large enough, something like: (((unsigned ptrdiff_t)(((char *)(NODE))-(char *)0) >> 2) % MAX_HASH_TABLE) Juki jtv@hut.fi
On 31 Jul 97 at 15:08, Jukka Virtanen wrote:
I suggest that this problem is fixed by casting the result of the pointer subtraction to (unsigned ptrdiff_t) which is always large enough, something like:
One slight problem: I couldn't find a `ptrdiff_t' in djgpp. However, it could always be created. Bill -- Leave others their otherness.
participants (3)
-
Bill Currie -
Jukka Virtanen -
Peter Gerwinski