Skip to content

Commit

Permalink
replay: check return values of fwrite
Browse files Browse the repository at this point in the history
This patch adds error reporting when fwrite cannot completely
save the buffer to the file.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Message-Id: <20180227095259.1060.86410.stgit@pasha-VirtualBox>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
  • Loading branch information
Dovgalyuk authored and bonzini committed Mar 12, 2018
1 parent d759c95 commit 6dc0f52
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions replay/replay-internal.c
Expand Up @@ -24,12 +24,23 @@
static QemuMutex lock;

/* File for replay writing */
static bool write_error;
FILE *replay_file;

static void replay_write_error(void)
{
if (!write_error) {
error_report("replay write error");
write_error = true;
}
}

void replay_put_byte(uint8_t byte)
{
if (replay_file) {
putc(byte, replay_file);
if (putc(byte, replay_file) == EOF) {
replay_write_error();
}
}
}

Expand Down Expand Up @@ -62,7 +73,9 @@ void replay_put_array(const uint8_t *buf, size_t size)
{
if (replay_file) {
replay_put_dword(size);
fwrite(buf, 1, size, replay_file);
if (fwrite(buf, 1, size, replay_file) != size) {
replay_write_error();
}
}
}

Expand Down

0 comments on commit 6dc0f52

Please sign in to comment.