Browse Source

tplink-safeloader: fix compilation warnings

Signed-off-by: Ilya Gordeev <Mirraz@users.noreply.github.com>
(cherry picked from commit 5daf09435311922cad32b66b75d13b9367db62f7)
Ilya Gordeev 4 years ago
parent
commit
ee715c63be
1 changed files with 13 additions and 12 deletions
  1. 13 12
      tools/firmware-utils/src/tplink-safeloader.c

+ 13 - 12
tools/firmware-utils/src/tplink-safeloader.c

@@ -1483,11 +1483,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);
 
@@ -1837,7 +1838,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 &&
@@ -1890,7 +1891,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';
@@ -1981,18 +1982,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");
 	}
 }
@@ -2045,7 +2046,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)
@@ -2061,7 +2062,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;
 	}
@@ -2073,19 +2074,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");
 	}
 }