diff mbox series

[13/88] Dirty Bitmaps: use g_new() family of functions

Message ID 20171006235023.11952-14-f4bug@amsat.org
State New
Headers show
Series use g_new() family of functions | expand

Commit Message

Philippe Mathieu-Daudé Oct. 6, 2017, 11:49 p.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
[PMD: squashed tests/test-hbitmap.c changes]
---
 tests/test-hbitmap.c | 2 +-
 util/hbitmap.c       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

John Snow Oct. 7, 2017, 3:45 p.m. UTC | #1
On 10/06/2017 07:49 PM, Philippe Mathieu-Daudé wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> [PMD: squashed tests/test-hbitmap.c changes]
> ---
>  tests/test-hbitmap.c | 2 +-
>  util/hbitmap.c       | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
> index af41642346..fea3a64712 100644
> --- a/tests/test-hbitmap.c
> +++ b/tests/test-hbitmap.c
> @@ -122,7 +122,7 @@ static void hbitmap_test_truncate_impl(TestHBitmapData *data,
>  
>      n = hbitmap_test_array_size(size);
>      m = hbitmap_test_array_size(data->old_size);
> -    data->bits = g_realloc(data->bits, sizeof(unsigned long) * n);
> +    data->bits = g_renew(unsigned long, data->bits, n);
>      if (n > m) {
>          memset(&data->bits[m], 0x00, sizeof(unsigned long) * (n - m));
>      }
> diff --git a/util/hbitmap.c b/util/hbitmap.c
> index 2f9d0fdbd0..4eb0188836 100644
> --- a/util/hbitmap.c
> +++ b/util/hbitmap.c
> @@ -668,7 +668,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size)
>          }
>          old = hb->sizes[i];
>          hb->sizes[i] = size;
> -        hb->levels[i] = g_realloc(hb->levels[i], size * sizeof(unsigned long));
> +        hb->levels[i] = g_renew(unsigned long, hb->levels[i], size);
>          if (!shrink) {
>              memset(&hb->levels[i][old], 0x00,
>                     (size - old) * sizeof(*hb->levels[i]));
> 

Hm, I guess g_renew() isn't a new addition to glib, and we can safely
use it.

Reviewed-by: John Snow <jsnow@redhat.com>

And for convenience, this can be staged by whomever wishes to stage the
whole 88 patch enchilada:

Acked-by: John Snow <jsnow@redhat.com>
diff mbox series

Patch

diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c
index af41642346..fea3a64712 100644
--- a/tests/test-hbitmap.c
+++ b/tests/test-hbitmap.c
@@ -122,7 +122,7 @@  static void hbitmap_test_truncate_impl(TestHBitmapData *data,
 
     n = hbitmap_test_array_size(size);
     m = hbitmap_test_array_size(data->old_size);
-    data->bits = g_realloc(data->bits, sizeof(unsigned long) * n);
+    data->bits = g_renew(unsigned long, data->bits, n);
     if (n > m) {
         memset(&data->bits[m], 0x00, sizeof(unsigned long) * (n - m));
     }
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 2f9d0fdbd0..4eb0188836 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -668,7 +668,7 @@  void hbitmap_truncate(HBitmap *hb, uint64_t size)
         }
         old = hb->sizes[i];
         hb->sizes[i] = size;
-        hb->levels[i] = g_realloc(hb->levels[i], size * sizeof(unsigned long));
+        hb->levels[i] = g_renew(unsigned long, hb->levels[i], size);
         if (!shrink) {
             memset(&hb->levels[i][old], 0x00,
                    (size - old) * sizeof(*hb->levels[i]));