[cc65] Bug in malloc()

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 1999-10-18 10:04:55


Hi!

Jesse Beach found an error in the malloc subroutine. The symptoms are:

    * malloc() returns NULL even if there is space left on the heap.

    * malloc() does not return NULL for large allocated blocks, even if
      there is not enough space left, leading to memory corruption.

In fact there is a single line in the subroutine that contains two errors at
once. The heap stuff was originally written for a 32 bit DSP with 32 bit data
types and a 24 bit address space, and it seems this line was not changed when
porting the module.

Here is the patch:

Index: malloc.c
===================================================================
RCS file: /usr/local/cvsroot/uz/c64/cc65/lib/common/malloc.c,v
retrieving revision 1.8
diff -r1.8 malloc.c
107c107
<         if (_hptr + size >= _hend) {
---
> 	if (((unsigned) _hend) - ((unsigned) _hptr) < size) {


The fix will be in the next official version, but I cannot currently promise
any release dates.

Regards


	Uz


--
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:45 CET