Use signed char cast to avoid out-of-range error on PowerPC (which has

unsigned char by default). This is a no-op on all other current arches.

Tested by: md5 sum before/after same on i386
This commit is contained in:
Peter Grehan 2004-02-25 00:52:14 +00:00
parent 986c9fbae8
commit 8509c106ef
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=126206

View File

@ -88,8 +88,9 @@ Malloc(size_t bytes, const char *file, int line)
#endif
res->ga_Bytes = bytes;
#ifdef USEENDGUARD
*((char *)res + bytes - 1) = -2;
*((signed char *)res + bytes - 1) = -2;
#endif
return((char *)res + MALLOCALIGN);
}
@ -113,13 +114,13 @@ Free(void *ptr, const char *file, int line)
res->ga_Magic = GAFREE;
#endif
#ifdef USEENDGUARD
if (*((char *)res + res->ga_Bytes - 1) == -1) {
if (*((signed char *)res + res->ga_Bytes - 1) == -1) {
printf("free: duplicate2 free @ %p from %s:%d\n", ptr, file, line);
return;
}
if (*((char *)res + res->ga_Bytes - 1) != -2)
if (*((signed char *)res + res->ga_Bytes - 1) != -2)
panic("free: guard2 fail @ %p + %d from %s:%d", ptr, res->ga_Bytes - MALLOCALIGN, file, line);
*((char *)res + res->ga_Bytes - 1) = -1;
*((signed char *)res + res->ga_Bytes - 1) = -1;
#endif
bytes = res->ga_Bytes;