NovaCoder:
In parts of the code it calls calloc() but passes in zero for the number variable (the first parameter). In other implementations this would just result in no memory being allocated and calloc() would simply return NULL but in gcc 68k it blows up!
Blows up how? Are you sure it's just calloc()? It could be that at some points malloc() is called with a zero length parameter, too.
If the code came from a Unix system, it's possible that it expects calloc() to return a non-NULL result if the first parameter is zero. This is actually permitted by the ISO 'C' language standard and its counterpart POSIX because some systems will return a non-NULL result if malloc(), which calloc() is built upon, receives a zero length parameter.
Optimistically called "implementation defined behaviour", you are in for a surprise if the system you deploy your code on is not sharing the relevant implementation details with the one it was developed for.
Here's one way to try this. Add you own calloc() function which works something like this:
void * calloc(size_t count,size_t size)
{
size_t total_size;
void * result;
total_size = count * size;
if(total_size == 0)
total_size = sizeof(void *); /* Or any size you prefer */
result = malloc(total_size);
if(result != NULL)
memset(result,0,total_size);
return(result);
}
This function returns a non-NULL result unless it runs out of memory. It will always allocate at least as much memory as is required to store a single pointer, which may or may not be enough.
Writing a malloc() replacement that returns a non-NULL result for a zero length parameter is tricker, though...