Opened 4 years ago

Closed 4 years ago

#109 closed defect (fixed)

libc: calloc forgets to set errno whenever it fails

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

Description

Hi, Divine fails to correctly verify following piece of code and the enclosed patch fixes the issue.

#include <assert.h>
#include <errno.h>
#include <stdlib.h>

int main(void)
{
    errno = 0;

    char *ptr = calloc(1, sizeof(char));
    if (ptr == NULL) {
        assert(errno == ENOMEM);
        return EXIT_SUCCESS;
    }

    assert(*ptr == 0);
    assert(errno == 0);
    free(ptr);
}

Output:

$ divine verify --leakcheck return 0005-test.c
compiling 0005-test.c                                                                          
loading bitcode … DiOS … LART … RR … constants … done                                          
booting … done                                                                                 
states per second: 117.647                                                                     
state count: 2                                                                                 
mips: 0.74                                                                                     
                                                                                               
error found: yes                                                                               
error trace: |                                                                                 
  FAULT: 0005-test.c:11: int main(void): assertion 'errno == ENOMEM' failed                    
  [0] FATAL: assertion failure in userspace                                                    
                                                                                               
active stack:                                                                                  
  - symbol: void __dios::FaultBase::handler<__dios::Context>(_VM_Fault, _VM_Frame*, void (*)())
    location: dios/sys/fault.hpp:119                                       
  - symbol: __dios_fault                                                                       
    location: dios/arch/divm/fault.c:12                                    
  - symbol: __assert_fail                                                                      
    location: dios/libc/_PDCLIB/assert.c:36                                
  - symbol: main                                                                               
    location: 0005-test.c:11                                                                   
  - symbol: __dios_start                                                                       
    location: dios/libc/sys/start.cpp:91                                   
a report was written to 0005-test.report 

Attachments (1)

calloc-errno.patch (478 bytes) - added by Lukáš Zaoral 4 years ago.

Download all attachments as: .zip

Change History (2)

Changed 4 years ago by Lukáš Zaoral

Attachment: calloc-errno.patch added

comment:1 Changed 4 years ago by Henrich Lauko

Resolution: fixed
Status: newclosed

Thanks for the patch.

Note: See TracTickets for help on using tickets.