Ignore:
Timestamp:
Mar 22, 2006, 6:34:03 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Handle malloc(0), realloc(NULL,...) and realloc(...,0) in kernel mode.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/kernel/kernel.c

    r652 r664  
    5656{
    5757    uint32_t *p = freemem;
     58    if(!size)
     59        return NULL;
    5860    size = (size + 0x7) / 4;
    5961    *p = size;
     
    6971void *realloc(void *ptr, size_t size)
    7072{
    71    uint32_t oldsize = ((uint32_t *)ptr)[-1];
     73    uint32_t oldsize;
    7274    void *p;
    73     if(oldsize >= size)
    74         return ptr;
     75
     76    if(!size)
     77        return NULL;
     78
     79    if(!ptr)
     80        oldsize = 0;
     81    else
     82    {
     83        oldsize = ((uint32_t *)ptr)[-1];
     84        if(oldsize >= size)
     85            return ptr;
     86    }
    7587
    7688    p = malloc(size);
Note: See TracChangeset for help on using the changeset viewer.