tests: Avoid malloc failures

test-display-streaming is calling malloc() without checking its return
value. Coverity warns about this. This commit switches to g_malloc() to
sidestep this warning (g_malloc() never returns NULL but aborts instead).
This commit is contained in:
Christophe Fergeau 2014-01-02 18:07:16 +01:00
parent 3ac428b4b7
commit 7d9018d441
2 changed files with 8 additions and 2 deletions

View File

@ -6,6 +6,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/server \
-I$(top_srcdir)/server/tests \
$(COMMON_CFLAGS) \
$(GLIB2_CFLAGS) \
$(SMARTCARD_CFLAGS) \
$(SPICE_NONPKGCONFIG_CFLAGS) \
$(NULL)
@ -17,6 +18,7 @@ endif
LDADD = \
$(top_builddir)/spice-common/common/libspice-common.la \
$(top_builddir)/server/libspice-server.la \
$(GLIB2_LIBS) \
$(NULL)
COMMON_BASE = \

View File

@ -5,12 +5,16 @@
*/
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <glib.h>
#include "test_display_base.h"
static int sized;
@ -29,7 +33,7 @@ static void create_overlay(Command *command , int width, int height)
cmd->bbox.bottom = height;
cmd->num_clip_rects = 0;
cmd->bitmap = malloc(width * height * 4 );
cmd->bitmap = g_malloc(width * height * 4 );
dst = (uint32_t *)cmd->bitmap;
for (int i = 0; i < width * height; i++, dst++) {
*dst = 0x8B008B;
@ -100,7 +104,7 @@ static void create_clipped_frame(Test *test, Command *command, int clipping_fact
end_line += 50;
}
cmd->bitmap = malloc(width*height*4);
cmd->bitmap = g_malloc(width*height*4);
memset(cmd->bitmap, 0xff, width*height*4);
dst = (uint32_t *)(cmd->bitmap + cur_line*width*4);
for (cur_line; cur_line < end_line; cur_line++) {