From 11f08dacc920dba49d932ccdf378331a32bad9d9 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Tue, 1 Sep 2020 21:14:39 +0200 Subject: [PATCH] pvck: add simple check for fwrite Add at least very light check for result code of fwrite(). --- tools/pvck.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/pvck.c b/tools/pvck.c index 73ef6ceff..302c74621 100644 --- a/tools/pvck.c +++ b/tools/pvck.c @@ -846,6 +846,7 @@ static int _dump_meta_area(struct device *dev, struct devicefile *def, const cha { FILE *fp; char *meta_buf; + int ret = 1; if (!tofile) return_0; @@ -866,7 +867,11 @@ static int _dump_meta_area(struct device *dev, struct devicefile *def, const cha return 0; } - fwrite(meta_buf, mda_size - 512, 1, fp); + if (fwrite(meta_buf, mda_size - 512, 1, fp) != 1) { + log_error("Failed to write file %s metadata area size %llu.", + tofile, (unsigned long long)mda_size); + ret = 0; + } free(meta_buf); @@ -874,7 +879,7 @@ static int _dump_meta_area(struct device *dev, struct devicefile *def, const cha stack; if (fclose(fp)) stack; - return 1; + return ret; } /* all sizes and offsets in bytes */ -- 2.43.5