Skip to contentSkip to conversation

ihex: fix unused return value compiler warning.

PATCH In review Chris Ruffin 2 participants 2 messages Jan 2, 2011 – Jan 3, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ihex: fix unused return value compiler warning.

fixed unusued return value compiler warnings due to unchecked write() calls.

---
 firmware/ihex2fw.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
firmware/ihex2fw.c +5 -4
index ba0cf0b..a079bdd 100644
@@ -124,8 +124,7 @@ int main(int argc, char **argv)
 	if (process_ihex(data, st.st_size))
 		return 1;
 
-	output_records(outfd);
-	return 0;
+	return output_records(outfd);
 }
 
 static int process_ihex(uint8_t *data, ssize_t size)
@@ -269,11 +268,13 @@ static int output_records(int outfd)
 
 		p->addr = htonl(p->addr);
 		p->len = htons(p->len);
-		write(outfd, &p->addr, writelen);
+		if (write(outfd, &p->addr, writelen) != writelen)
+			return errno;
 		p = p->next;
 	}
 	/* EOF record is zero length, since we don't bother to represent
 	   the type field in the binary version */
-	write(outfd, zeroes, 6);
+	if (write(outfd, zeroes, 6) != 6)
+		return errno;
 	return 0;
 }
Signature · 1 line
1.7.1
#1 lore raw
Quoted 27 lines · On Sun, 2 Jan 2011 11:27:10 -0800 Chris Ruffin <[email protected]> wrote:

fixed unusued return value compiler warnings due to unchecked write() calls.

---
 firmware/ihex2fw.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
firmware/ihex2fw.c +2 -3
index ba0cf0b..a079bdd 100644
@@ -124,8 +124,7 @@ int main(int argc, char **argv)
 	if (process_ihex(data, st.st_size))
 		return 1;
 
-	output_records(outfd);
-	return 0;
+	return output_records(outfd);
 }
 
 static int process_ihex(uint8_t *data, ssize_t size)
@@ -269,11 +268,13 @@ static int output_records(int outfd)
 
 		p->addr = htonl(p->addr);
 		p->len = htons(p->len);
-		write(outfd, &p->addr, writelen);
+		if (write(outfd, &p->addr, writelen) != writelen)

firmware/ihex2fw.c static int output_records(int outfd) · line 280

Quoted 10 lines
firmware/ihex2fw.c +3 -1
+			return errno;
 		p = p->next;
 	}
 	/* EOF record is zero length, since we don't bother to represent
 	   the type field in the binary version */
-	write(outfd, zeroes, 6);
+	if (write(outfd, zeroes, 6) != 6)
+		return errno;
 	return 0;
 }

write(1) will only set errno if it returned -1. So in the case where write() returned a positive number less than count', output_records() will return a garbage value of errno'.

I guess this will suffice:

firmware/ihex2fw.c renamed from firmware/ihex2fw.c~ihex-fix-unused-return-value-compiler-warning-fix +2 -2
@@ -269,12 +269,12 @@ static int output_records(int outfd)
 		p->addr = htonl(p->addr);
 		p->len = htons(p->len);
 		if (write(outfd, &p->addr, writelen) != writelen)
-			return errno;
+			return 1;
 		p = p->next;
 	}
 	/* EOF record is zero length, since we don't bother to represent
 	   the type field in the binary version */
 	if (write(outfd, zeroes, 6) != 6)
-		return errno;
+		return 1;
 	return 0;
 }

_