Changeset 1370


Ignore:
Timestamp:
07/13/11 00:35:21 (10 months ago)
Author:
stefanct
Message:

fix unchecked malloc calls and casts of malloc return values

in the long term the exit calls should be replaced by returns.
until then this is the correct way to handle failures.

the casts are not needed (in C) and we don't cast malloc return values anywhere else.

Signed-off-by: Stefan Tauner <stefan.tauner@…>
Acked-by: Uwe Hermann <uwe@…>

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/flashrom.c

    r1364 r1370  
    15141514 
    15151515        msg_cinfo("Erasing and writing flash chip... "); 
    1516         curcontents = (uint8_t *) malloc(size); 
     1516        curcontents = malloc(size); 
     1517        if (!curcontents) { 
     1518                msg_gerr("Out of memory!\n"); 
     1519                exit(1); 
     1520        } 
    15171521        /* Copy oldcontents to curcontents to avoid clobbering oldcontents. */ 
    15181522        memcpy(curcontents, oldcontents, size); 
     
    18811885        } 
    18821886 
    1883         oldcontents = (uint8_t *) malloc(size); 
     1887        oldcontents = malloc(size); 
     1888        if (!oldcontents) { 
     1889                msg_gerr("Out of memory!\n"); 
     1890                exit(1); 
     1891        } 
    18841892        /* Assume worst case: All bits are 0. */ 
    18851893        memset(oldcontents, 0x00, size); 
    1886         newcontents = (uint8_t *) malloc(size); 
     1894        newcontents = malloc(size); 
     1895        if (!newcontents) { 
     1896                msg_gerr("Out of memory!\n"); 
     1897                exit(1); 
     1898        } 
    18871899        /* Assume best case: All bits should be 1. */ 
    18881900        memset(newcontents, 0xff, size); 
  • trunk/hwaccess.c

    r1338 r1370  
    227227        struct undo_mmio_write_data *undo_mmio_write_data;              \ 
    228228        undo_mmio_write_data = malloc(sizeof(struct undo_mmio_write_data)); \ 
     229        if (!undo_mmio_write_data) {                                    \ 
     230                msg_gerr("Out of memory!\n");                           \ 
     231                exit(1);                                                \ 
     232        }                                                               \ 
    229233        undo_mmio_write_data->addr = a;                                 \ 
    230234        undo_mmio_write_data->type = mmio_write_type_##c;               \ 
  • trunk/pcidev.c

    r1338 r1370  
    296296        struct undo_pci_write_data *undo_pci_write_data;                \ 
    297297        undo_pci_write_data = malloc(sizeof(struct undo_pci_write_data)); \ 
     298        if (!undo_pci_write_data) {                                     \ 
     299                msg_gerr("Out of memory!\n");                           \ 
     300                exit(1);                                                \ 
     301        }                                                               \ 
    298302        undo_pci_write_data->dev = *a;                                  \ 
    299303        undo_pci_write_data->reg = b;                                   \ 
  • trunk/serial.c

    r1363 r1370  
    111111            (tolower((unsigned char)dev[2]) == 'm')) { 
    112112                dev2 = malloc(strlen(dev) + 5); 
     113                if (!dev2) 
     114                        sp_die("Error: Out of memory"); 
    113115                strcpy(dev2, "\\\\.\\"); 
    114116                strcpy(dev2 + 4, dev); 
Note: See TracChangeset for help on using the changeset viewer.