From aca1d172493a837f12c6609694a4520d82b69648 Mon Sep 17 00:00:00 2001 From: Sergey Gridassov Date: Fri, 10 Dec 2010 17:02:51 +0300 Subject: [PATCH] Fixed 'unused result' warnings --- Makefile | 2 +- ingenic.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c43c028..c201db8 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ endif CC = gcc TARGET = jzboot SOURCES = debug.c devmgr.c ingenic.c main.c shell_lex.c usbdev.c shell.c shell_builtins.c config.c spl_cmdset.c usbboot_cmdset.c -CFLAGS = --std=gnu99 -Wall -Werror -O2 $(shell pkg-config libusb-1.0 --cflags) +CFLAGS = --std=gnu99 -Wall -Werror -O2 $(shell pkg-config libusb-1.0 --cflags) -Wunused-result LIBS += $(shell pkg-config libusb-1.0 --libs) OBJECTS = ${SOURCES:.c=.o} diff --git a/ingenic.c b/ingenic.c index dd302bc..5d84253 100644 --- a/ingenic.c +++ b/ingenic.c @@ -290,10 +290,18 @@ int ingenic_loadstage(void *hndl, int id, const char *file) { fseek(fd, 0, SEEK_SET); void *data = malloc(size); - fread(data, size, 1, fd); + size_t read_bytes = fread(data, size, 1, fd); fclose(fd); + if(read_bytes != size) { + free(data); + + errno = EIO; + + return -1; + } + memcpy(data + 8, &handle->cfg, sizeof(firmware_config_t)); if(ingenic_wordop(handle->usb, VR_SET_DATA_ADDRESS, base) == -1) { @@ -452,10 +460,18 @@ int ingenic_load_sdram_file(void *hndl, uint32_t base, const char *file) { fseek(fd, 0, SEEK_SET); void *data = malloc(size); - fread(data, size, 1, fd); + size_t bytes = fread(data, size, 1, fd); fclose(fd); + if(bytes != size) { + free(data); + + errno = EIO; + + return -1; + } + int ret = ingenic_load_sdram(handle, data, base, size); free(data);