Patchwork [1/8] buffered_file: g_realloc() can't fail

login
register
mail settings
Submitter Juan Quintela
Date Aug. 18, 2012, 11:17 a.m.
Message ID <1345288635-1369-2-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/178446/
State New
Headers show

Comments

Juan Quintela - Aug. 18, 2012, 11:17 a.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 buffered_file.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
Orit Wasserman - Aug. 21, 2012, 10:40 a.m.
On 08/18/2012 02:17 PM, Juan Quintela wrote:
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  buffered_file.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/buffered_file.c b/buffered_file.c
> index f170aa0..4148abb 100644
> --- a/buffered_file.c
> +++ b/buffered_file.c
> @@ -50,20 +50,12 @@ static void buffered_append(QEMUFileBuffered *s,
>                              const uint8_t *buf, size_t size)
>  {
>      if (size > (s->buffer_capacity - s->buffer_size)) {
> -        void *tmp;
> -
>          DPRINTF("increasing buffer capacity from %zu by %zu\n",
>                  s->buffer_capacity, size + 1024);
> 
>          s->buffer_capacity += size + 1024;
> 
> -        tmp = g_realloc(s->buffer, s->buffer_capacity);
> -        if (tmp == NULL) {
> -            fprintf(stderr, "qemu file buffer expansion failed\n");
> -            exit(1);
> -        }
> -
> -        s->buffer = tmp;
> +        s->buffer = g_realloc(s->buffer, s->buffer_capacity);
>      }
> 
>      memcpy(s->buffer + s->buffer_size, buf, size);
> 

Reviewed-by: Orit Wasserman <owasserm@redhat.com>

Patch

diff --git a/buffered_file.c b/buffered_file.c
index f170aa0..4148abb 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -50,20 +50,12 @@  static void buffered_append(QEMUFileBuffered *s,
                             const uint8_t *buf, size_t size)
 {
     if (size > (s->buffer_capacity - s->buffer_size)) {
-        void *tmp;
-
         DPRINTF("increasing buffer capacity from %zu by %zu\n",
                 s->buffer_capacity, size + 1024);

         s->buffer_capacity += size + 1024;

-        tmp = g_realloc(s->buffer, s->buffer_capacity);
-        if (tmp == NULL) {
-            fprintf(stderr, "qemu file buffer expansion failed\n");
-            exit(1);
-        }
-
-        s->buffer = tmp;
+        s->buffer = g_realloc(s->buffer, s->buffer_capacity);
     }

     memcpy(s->buffer + s->buffer_size, buf, size);