From: Andrew Cooper Subject: [PATCH 1/2] tools/libxl: Assert success of memory allocation in testidl Date: Fri, 7 Aug 2015 15:06:23 +0100 Message-ID: <1438956384-7309-2-git-send-email-andrew.cooper3@citrix.com> References: <1438956384-7309-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1438956384-7309-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Ian Jackson , Ian Campbell , Wei Liu List-Id: xen-devel@lists.xenproject.org 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 --- CC: Ian Campbell CC: Ian Jackson CC: Wei Liu --- 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 #include #include +#include #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; isize = 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