summaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2011-07-12 22:35:21 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2011-07-12 22:35:21 +0000
commit269de3533ac58de85bf874afcbc862d73e1944c7 (patch)
treeee762ee7695c977df7c4174fb263308a26b543cf /flashrom.c
parentff56267ec0ffefa071f26c22553b9bea216d19f7 (diff)
downloadast2050-flashrom-269de3533ac58de85bf874afcbc862d73e1944c7.zip
ast2050-flashrom-269de3533ac58de85bf874afcbc862d73e1944c7.tar.gz
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. Corresponding to flashrom svn r1370. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/flashrom.c b/flashrom.c
index d5892ca..998a18f 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1513,7 +1513,11 @@ int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents, uint8_t
unsigned int usable_erasefunctions = count_usable_erasers(flash);
msg_cinfo("Erasing and writing flash chip... ");
- curcontents = (uint8_t *) malloc(size);
+ curcontents = malloc(size);
+ if (!curcontents) {
+ msg_gerr("Out of memory!\n");
+ exit(1);
+ }
/* Copy oldcontents to curcontents to avoid clobbering oldcontents. */
memcpy(curcontents, oldcontents, size);
@@ -1880,10 +1884,18 @@ int doit(struct flashchip *flash, int force, const char *filename, int read_it,
goto out_nofree;
}
- oldcontents = (uint8_t *) malloc(size);
+ oldcontents = malloc(size);
+ if (!oldcontents) {
+ msg_gerr("Out of memory!\n");
+ exit(1);
+ }
/* Assume worst case: All bits are 0. */
memset(oldcontents, 0x00, size);
- newcontents = (uint8_t *) malloc(size);
+ newcontents = malloc(size);
+ if (!newcontents) {
+ msg_gerr("Out of memory!\n");
+ exit(1);
+ }
/* Assume best case: All bits should be 1. */
memset(newcontents, 0xff, size);
/* Side effect of the assumptions above: Default write action is erase
OpenPOWER on IntegriCloud