[RFC,v2,21/26] replay: check return values of fwrite

Message ID 20171114081829.27640.69432.stgit@pasha-VirtualBox
State New
Headers show
Series
  • replay additions
Related show

Commit Message

Pavel Dovgalyuk Nov. 14, 2017, 8:18 a.m.
This patch adds error reporting when fwrite cannot completely
save the buffer to the file.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>

---
 replay/replay-internal.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Paolo Bonzini Nov. 14, 2017, 1:37 p.m. | #1
On 14/11/2017 09:18, Pavel Dovgalyuk wrote:
> This patch adds error reporting when fwrite cannot completely
> save the buffer to the file.
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
> 
> ---
>  replay/replay-internal.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/replay/replay-internal.c b/replay/replay-internal.c
> index a1a7686..1888400 100644
> --- a/replay/replay-internal.c
> +++ b/replay/replay-internal.c
> @@ -62,7 +62,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) {
> +            error_report("replay write error");
> +        }
>      }
>  }
>  
> 

Should the error be printed only once?  In addition, putc is not tested
in the same way.

Paolo

Patch

diff --git a/replay/replay-internal.c b/replay/replay-internal.c
index a1a7686..1888400 100644
--- a/replay/replay-internal.c
+++ b/replay/replay-internal.c
@@ -62,7 +62,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) {
+            error_report("replay write error");
+        }
     }
 }