summaryrefslogtreecommitdiff
path: root/cat
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@gmail.com>2016-04-28 19:44:20 -0700
committerTim Kientzle <kientzle@gmail.com>2016-04-28 19:44:20 -0700
commitebc67c17dedcfd1d0d6c11e101f53f57d6f26075 (patch)
tree1f6f0cfe4525a210b145798885fed06a7026b586 /cat
parentc917762d6d90a430458bd728c882242544bc8955 (diff)
downloadlibarchive-ebc67c17dedcfd1d0d6c11e101f53f57d6f26075.tar.gz
Issue 695: check fwrite return value, sync up test harnesses
Diffstat (limited to 'cat')
-rw-r--r--cat/test/main.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/cat/test/main.c b/cat/test/main.c
index 8c414da1..319f68c7 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);