Skip to contentSkip to conversation

usemem: Fix the build warning

PATCH In review Hui Zhu 2 participants 2 messages Dec 25, 2019

lore
Share & tools
lore

Hui Zhu

author
#0 lore raw

PATCH 1/1 usemem: Fix the build warning

Got:
gcc -O -c -Wall -g usemem.c -o usemem.o
usemem.c: In function ‘output_statistics’:
usemem.c:638:2: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
write(1, buf, len);

This commit fixes this warning.

---
 usemem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
usemem.c +2 -1
index 85dbdc5..9158304 100644
@@ -635,7 +635,8 @@ static void output_statistics(unsigned long unit_bytes, const char *intro)
 			"%s%lu bytes / %lu usecs = %lu KB/s\n",
 			intro, unit_bytes, delta_us, throughput);
 	fflush(stdout);
-	write(1, buf, len);
+	if (write(1, buf, len) != len)
+		printf("Output buf \"%s\" fail\n", buf);
 }
 
 static void timing_free(void *ptrs[], unsigned int nptr,
Signature · 1 line
2.7.4
#1 lore raw

Thanks teawater!

usemem.c static void output_statistics(unsigned long unit_bytes, const char *intro) · line 639

Quoted 3 lines
usemem.c +2 -1
-	write(1, buf, len);
+	if (write(1, buf, len) != len)
+		printf("Output buf \"%s\" fail\n", buf);

Changed it to

               fprintf(stderr, "WARNING: statistics output may be incomplete.\n");

Thanks,
Fengguang