From 5daf09435311922cad32b66b75d13b9367db62f7 Mon Sep 17 00:00:00 2001 From: Ilya Gordeev Date: Sat, 12 Oct 2019 23:10:09 +0500 Subject: tplink-safeloader: fix compilation warnings Signed-off-by: Ilya Gordeev --- tools/firmware-utils/src/tplink-safeloader.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'tools/firmware-utils') diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c index 8dc72c9f43..2a57aefd14 100644 --- a/tools/firmware-utils/src/tplink-safeloader.c +++ b/tools/firmware-utils/src/tplink-safeloader.c @@ -1684,11 +1684,12 @@ static struct image_partition_entry read_file(const char *part_name, const char size_t len = statbuf.st_size; - if (add_jffs2_eof) + if (add_jffs2_eof) { if (file_system_partition) len = ALIGN(len + file_system_partition->base, 0x10000) + sizeof(jffs2_eof_mark) - file_system_partition->base; else len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark); + } struct image_partition_entry entry = alloc_image_partition(part_name, len); @@ -2038,7 +2039,7 @@ static int add_flash_partition( unsigned long base, unsigned long size) { - int ptr; + size_t ptr; /* check if the list has a free entry */ for (ptr = 0; ptr < max_entries; ptr++, part_list++) { if (part_list->name == NULL && @@ -2091,7 +2092,7 @@ static int read_partition_table( if (fseek(file, offset, SEEK_SET) < 0) error(1, errno, "Can not seek in the firmware"); - if (fread(buf, 1, 2048, file) < 0) + if (fread(buf, 2048, 1, file) != 1) error(1, errno, "Can not read fwup-ptn from the firmware"); buf[2047] = '\0'; @@ -2182,18 +2183,18 @@ static void write_partition( fseek(input_file, entry->base + firmware_offset, SEEK_SET); for (offset = 0; sizeof(buf) + offset <= entry->size; offset += sizeof(buf)) { - if (fread(buf, sizeof(buf), 1, input_file) < 0) + if (fread(buf, sizeof(buf), 1, input_file) != 1) error(1, errno, "Can not read partition from input_file"); - if (fwrite(buf, sizeof(buf), 1, output_file) < 0) + if (fwrite(buf, sizeof(buf), 1, output_file) != 1) error(1, errno, "Can not write partition to output_file"); } /* write last chunk smaller than buffer */ if (offset < entry->size) { offset = entry->size - offset; - if (fread(buf, offset, 1, input_file) < 0) + if (fread(buf, offset, 1, input_file) != 1) error(1, errno, "Can not read partition from input_file"); - if (fwrite(buf, offset, 1, output_file) < 0) + if (fwrite(buf, offset, 1, output_file) != 1) error(1, errno, "Can not write partition to output_file"); } } @@ -2246,7 +2247,7 @@ static int extract_firmware(const char *input, const char *output_directory) error(1, 0, "Error can not read the partition table (fwup-ptn)"); } - for (int i = 0; i < max_entries; i++) { + for (size_t i = 0; i < max_entries; i++) { if (entries[i].name == NULL && entries[i].base == 0 && entries[i].size == 0) @@ -2262,7 +2263,7 @@ static struct flash_partition_entry *find_partition( struct flash_partition_entry *entries, size_t max_entries, const char *name, const char *error_msg) { - for (int i = 0; i < max_entries; i++, entries++) { + for (size_t i = 0; i < max_entries; i++, entries++) { if (strcmp(entries->name, name) == 0) return entries; } @@ -2274,19 +2275,19 @@ static struct flash_partition_entry *find_partition( static void write_ff(FILE *output_file, size_t size) { char buf[4096]; - int offset; + size_t offset; memset(buf, 0xff, sizeof(buf)); for (offset = 0; offset + sizeof(buf) < size ; offset += sizeof(buf)) { - if (fwrite(buf, sizeof(buf), 1, output_file) < 0) + if (fwrite(buf, sizeof(buf), 1, output_file) != 1) error(1, errno, "Can not write 0xff to output_file"); } /* write last chunk smaller than buffer */ if (offset < size) { offset = size - offset; - if (fwrite(buf, offset, 1, output_file) < 0) + if (fwrite(buf, offset, 1, output_file) != 1) error(1, errno, "Can not write partition to output_file"); } } -- cgit v1.2.3