Re: [PATCH spice-server 07/16] test-display-base: Use spice allocation helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 04, 2017 at 11:57:15AM +0100, Frediano Ziglio wrote:
> Do not use calloc and malloc directly without checking
> the result. Use instead spice functions to get a nice
> error in case of allocation failures.

I'd tend to switch to g_new0 and friends rather than spice_xxx...

Christophe

> 
> Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
> ---
>  server/tests/test-display-base.c | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/server/tests/test-display-base.c b/server/tests/test-display-base.c
> index d6b2dd07..c6e47bec 100644
> --- a/server/tests/test-display-base.c
> +++ b/server/tests/test-display-base.c
> @@ -185,7 +185,7 @@ test_spice_create_update_from_bitmap(uint32_t surface_id,
>      bh = bbox.bottom - bbox.top;
>      bw = bbox.right - bbox.left;
>  
> -    update   = calloc(sizeof(*update), 1);
> +    update   = spice_new0(SimpleSpiceUpdate, 1);
>      update->bitmap = bitmap;
>      drawable = &update->drawable;
>      image    = &update->image;
> @@ -198,7 +198,7 @@ test_spice_create_update_from_bitmap(uint32_t surface_id,
>      } else {
>          QXLClipRects *cmd_clip;
>  
> -        cmd_clip = calloc(sizeof(QXLClipRects) + num_clip_rects*sizeof(QXLRect), 1);
> +        cmd_clip = spice_malloc0(sizeof(QXLClipRects) + num_clip_rects*sizeof(QXLRect));
>          cmd_clip->num_rects = num_clip_rects;
>          cmd_clip->chunk.data_size = num_clip_rects*sizeof(QXLRect);
>          cmd_clip->chunk.prev_chunk = cmd_clip->chunk.next_chunk = 0;
> @@ -247,7 +247,7 @@ static SimpleSpiceUpdate *test_spice_create_update_solid(uint32_t surface_id, QX
>      bw = bbox.right - bbox.left;
>      bh = bbox.bottom - bbox.top;
>  
> -    bitmap = malloc(bw * bh * 4);
> +    bitmap = spice_malloc(bw * bh * 4);
>      dst = (uint32_t *)bitmap;
>  
>      for (i = 0 ; i < bh * bw ; ++i, ++dst) {
> @@ -282,7 +282,7 @@ static SimpleSpiceUpdate *test_spice_create_update_draw(Test *test, uint32_t sur
>      bw       = test->primary_width/SINGLE_PART;
>      bh       = 48;
>  
> -    bitmap = dst = malloc(bw * bh * 4);
> +    bitmap = dst = spice_malloc(bw * bh * 4);
>      //printf("allocated %p\n", dst);
>  
>      for (i = 0 ; i < bh * bw ; ++i, dst+=4) {
> @@ -307,7 +307,7 @@ static SimpleSpiceUpdate *test_spice_create_update_copy_bits(Test *test, uint32_
>          .top = 0,
>      };
>  
> -    update   = calloc(sizeof(*update), 1);
> +    update   = spice_new0(SimpleSpiceUpdate, 1);
>      drawable = &update->drawable;
>  
>      bw       = test->primary_width/SINGLE_PART;
> @@ -352,7 +352,7 @@ static int format_to_bpp(int format)
>  
>  static SimpleSurfaceCmd *create_surface(int surface_id, int format, int width, int height, uint8_t *data)
>  {
> -    SimpleSurfaceCmd *simple_cmd = calloc(sizeof(SimpleSurfaceCmd), 1);
> +    SimpleSurfaceCmd *simple_cmd = spice_new0(SimpleSurfaceCmd, 1);
>      QXLSurfaceCmd *surface_cmd = &simple_cmd->surface_cmd;
>      int bpp = format_to_bpp(format);
>  
> @@ -371,7 +371,7 @@ static SimpleSurfaceCmd *create_surface(int surface_id, int format, int width, i
>  
>  static SimpleSurfaceCmd *destroy_surface(int surface_id)
>  {
> -    SimpleSurfaceCmd *simple_cmd = calloc(sizeof(SimpleSurfaceCmd), 1);
> +    SimpleSurfaceCmd *simple_cmd = spice_new0(SimpleSurfaceCmd, 1);
>      QXLSurfaceCmd *surface_cmd = &simple_cmd->surface_cmd;
>  
>      set_cmd(&simple_cmd->ext, QXL_CMD_SURFACE, (intptr_t)surface_cmd);
> @@ -730,8 +730,8 @@ static int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext)
>      }
>  
>      test->cursor_notify--;
> -    cmd = calloc(sizeof(QXLCommandExt), 1);
> -    cursor_cmd = calloc(sizeof(QXLCursorCmd), 1);
> +    cmd = spice_new0(QXLCommandExt, 1);
> +    cursor_cmd = spice_new0(QXLCursorCmd, 1);
>  
>      cursor_cmd->release_info.id = (unsigned long)cmd;
>  
> @@ -886,8 +886,7 @@ void test_set_simple_command_list(Test *test, const int *simple_commands, int nu
>      int i;
>  
>      free(test->commands);
> -    test->commands = malloc(sizeof(*test->commands) * num_commands);
> -    memset(test->commands, 0, sizeof(*test->commands) * num_commands);
> +    test->commands = spice_new0(Command, num_commands);
>      test->num_commands = num_commands;
>      for (i = 0 ; i < num_commands; ++i) {
>          test->commands[i].command = simple_commands[i];
> -- 
> 2.13.5
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]