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

[Xen-devel] [PATCH 1/2] tools/libxl: Assert success of memory allocation in testidl



The chances of an allocation failing are slim but nonzero.  Assert
success of each allocation to quieten Coverity, which re-notices defects
each time the IDL changes.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CC: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/libxl/gentest.py |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/libxl/gentest.py b/tools/libxl/gentest.py
index 7621a1e..85311e7 100644
--- a/tools/libxl/gentest.py
+++ b/tools/libxl/gentest.py
@@ -33,6 +33,7 @@ def gen_rand_init(ty, v, indent = "    ", parent = None):
         s += "%s = rand()%%8;\n" % (parent + ty.lenvar.name)
         s += "%s = calloc(%s, sizeof(*%s));\n" % \
             (v, parent + ty.lenvar.name, v)
+        s += "assert(%s);\n" % (v, )
         s += "{\n"
         s += "    int i;\n"
         s += "    for (i=0; i<%s; i++)\n" % (parent + ty.lenvar.name)
@@ -98,6 +99,7 @@ if __name__ == '__main__':
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #include "libxl.h"
 #include "libxl_utils.h"
@@ -106,6 +108,7 @@ static char *rand_str(void)
 {
     int i, sz = rand() % 32;
     char *s = malloc(sz+1);
+    assert(s);
     for (i=0; i<sz; i++)
         s[i] = 'a' + (rand() % 26);
     s[i] = '\\0';
@@ -124,6 +127,7 @@ static void libxl_bitmap_rand_init(libxl_bitmap *bitmap)
     int i;
     bitmap->size = rand() % 16;
     bitmap->map = calloc(bitmap->size, sizeof(*bitmap->map));
+    assert(bitmap->map);
     libxl_for_each_bit(i, *bitmap) {
         if (rand() % 2)
             libxl_bitmap_set(bitmap, i);
@@ -136,6 +140,7 @@ static void 
libxl_key_value_list_rand_init(libxl_key_value_list *pkvl)
 {
     int i, nr_kvp = rand() % 16;
     libxl_key_value_list kvl = calloc(nr_kvp+1, 2*sizeof(char *));
+    assert(kvl);
 
     for (i = 0; i<2*nr_kvp; i += 2) {
         kvl[i] = rand_str();
@@ -196,6 +201,7 @@ static void libxl_string_list_rand_init(libxl_string_list 
*p)
 {
     int i, nr = rand() % 16;
     libxl_string_list l = calloc(nr+1, sizeof(char *));
+    assert(l);
 
     for (i = 0; i<nr; i++) {
         l[i] = rand_str();
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.