Opened 7 months ago

Last modified 7 months ago

#111 accepted defect

libc: zero size allocations are handled improperly

Reported by: Lukáš Zaoral Owned by: Henrich Lauko
Priority: major Milestone: 4.4
Component: DiOS Keywords:
Cc: kdudka@…, lzaoral@…

Description

Hi,
whenever a zero size allocation occurs, DiOS' implementation of {m,c,re}aloc sets errno to ENOMEM, which is a correct behaviour (at least according to POSIX.1-2017). However, just returning NULL in such case is not desirable, because Divine would never find following errors:

1.

#include <stdlib.h>

int main(void)
{
    char *ptr = malloc(0);
    if (ptr == NULL)
        return EXIT_SUCCESS;

    (void) *ptr; /* error */
    free(ptr);
}

2.

#include <stdlib.h>

int main(void)
{
    char *ptr = malloc(0);
    if (ptr == NULL)
        return EXIT_SUCCESS;

    /* possible leak */
}

Change History (2)

comment:1 Changed 7 months ago by Henrich Lauko

Owner: set to Henrich Lauko
Status: newassigned

comment:2 Changed 7 months ago by Henrich Lauko

Status: assignedaccepted
Note: See TracTickets for help on using tickets.