From 2e91d29ae9dd4646b9feaddf75e06ad52d9657da Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Tue, 21 Mar 2023 10:52:24 +0100 Subject: [PATCH] Check fwrite return value --- src/emu/pv/cfg.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/emu/pv/cfg.c b/src/emu/pv/cfg.c index 3384fb7..aef01b8 100644 --- a/src/emu/pv/cfg.c +++ b/src/emu/pv/cfg.c @@ -34,14 +34,20 @@ copy_file(const char *src, const char *dst) return -1; } + int ret = 0; size_t bytes; - while ((bytes = fread(buffer, 1, sizeof(buffer), infile)) > 0) - fwrite(buffer, 1, bytes, outfile); + while ((bytes = fread(buffer, 1, sizeof(buffer), infile)) > 0) { + if (fwrite(buffer, 1, bytes, outfile) != bytes) { + err("fwrite failed"); + ret = -1; + break; + } + } fclose(outfile); fclose(infile); - return 0; + return ret; } static int