From: Tim Kientzle Date: Fri, 29 Apr 2016 02:44:20 +0000 (-0700) Subject: Issue 695: check fwrite return value, sync up test harnesses X-Git-Tag: v3.2.0~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ebc67c17dedcfd1d0d6c11e101f53f57d6f26075;p=thirdparty%2Flibarchive.git Issue 695: check fwrite return value, sync up test harnesses --- diff --git a/cat/test/main.c b/cat/test/main.c index 8c414da14..319f68c77 100644 --- a/cat/test/main.c +++ b/cat/test/main.c @@ -780,6 +780,34 @@ assertion_equal_mem(const char *file, int line, return (0); } +/* Verify that a block of memory is filled with the specified byte. */ +int +assertion_memory_filled_with(const char *file, int line, + const void *_v1, const char *vd, + size_t l, const char *ld, + char b, const char *bd, void *extra) +{ + const char *v1 = (const char *)_v1; + size_t c = 0; + size_t i; + (void)ld; /* UNUSED */ + + assertion_count(file, line); + + for (i = 0; i < l; ++i) { + if (v1[i] == b) { + ++c; + } + } + if (c == l) + return (1); + + failure_start(file, line, "%s (size %d) not filled with %s", vd, (int)l, bd); + logprintf(" Only %d bytes were correct\n", (int)c); + failure_finish(extra); + return (0); +} + /* Verify that the named file exists and is empty. */ int assertion_empty_file(const char *filename, int line, const char *f1) @@ -2276,7 +2304,10 @@ copy_reference_file(const char *name) /* Not a lot of error checking here; the input better be right. */ out = fopen(name, "wb"); while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) { - fwrite(buff, 1, rbytes, out); + if (fwrite(buff, 1, rbytes, out) != rbytes) { + logprintf("Error: fwrite\n"); + break; + } } fclose(out); fclose(in); diff --git a/cpio/test/main.c b/cpio/test/main.c index 580112744..fa22adfbc 100644 --- a/cpio/test/main.c +++ b/cpio/test/main.c @@ -781,6 +781,34 @@ assertion_equal_mem(const char *file, int line, return (0); } +/* Verify that a block of memory is filled with the specified byte. */ +int +assertion_memory_filled_with(const char *file, int line, + const void *_v1, const char *vd, + size_t l, const char *ld, + char b, const char *bd, void *extra) +{ + const char *v1 = (const char *)_v1; + size_t c = 0; + size_t i; + (void)ld; /* UNUSED */ + + assertion_count(file, line); + + for (i = 0; i < l; ++i) { + if (v1[i] == b) { + ++c; + } + } + if (c == l) + return (1); + + failure_start(file, line, "%s (size %d) not filled with %s", vd, (int)l, bd); + logprintf(" Only %d bytes were correct\n", (int)c); + failure_finish(extra); + return (0); +} + /* Verify that the named file exists and is empty. */ int assertion_empty_file(const char *filename, int line, const char *f1) @@ -2277,7 +2305,10 @@ copy_reference_file(const char *name) /* Not a lot of error checking here; the input better be right. */ out = fopen(name, "wb"); while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) { - fwrite(buff, 1, rbytes, out); + if (fwrite(buff, 1, rbytes, out) != rbytes) { + logprintf("Error: fwrite\n"); + break; + } } fclose(out); fclose(in); diff --git a/libarchive/test/main.c b/libarchive/test/main.c index 8561129a8..e0af4314e 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -2303,7 +2303,10 @@ copy_reference_file(const char *name) /* Not a lot of error checking here; the input better be right. */ out = fopen(name, "wb"); while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) { - fwrite(buff, 1, rbytes, out); + if (fwrite(buff, 1, rbytes, out) != rbytes) { + logprintf("Error: fwrite\n"); + break; + } } fclose(out); fclose(in); diff --git a/tar/test/main.c b/tar/test/main.c index 33a6364b2..90801a98b 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -781,6 +781,34 @@ assertion_equal_mem(const char *file, int line, return (0); } +/* Verify that a block of memory is filled with the specified byte. */ +int +assertion_memory_filled_with(const char *file, int line, + const void *_v1, const char *vd, + size_t l, const char *ld, + char b, const char *bd, void *extra) +{ + const char *v1 = (const char *)_v1; + size_t c = 0; + size_t i; + (void)ld; /* UNUSED */ + + assertion_count(file, line); + + for (i = 0; i < l; ++i) { + if (v1[i] == b) { + ++c; + } + } + if (c == l) + return (1); + + failure_start(file, line, "%s (size %d) not filled with %s", vd, (int)l, bd); + logprintf(" Only %d bytes were correct\n", (int)c); + failure_finish(extra); + return (0); +} + /* Verify that the named file exists and is empty. */ int assertion_empty_file(const char *filename, int line, const char *f1) @@ -2277,7 +2305,10 @@ copy_reference_file(const char *name) /* Not a lot of error checking here; the input better be right. */ out = fopen(name, "wb"); while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) { - fwrite(buff, 1, rbytes, out); + if (fwrite(buff, 1, rbytes, out) != rbytes) { + logprintf("Error: fwrite\n"); + break; + } } fclose(out); fclose(in);