|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] tools/libxl: Assert success of memory allocation in testidl
commit 4289820507df2913300d9fe6caf733e0600f0d54
Author: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Fri Aug 7 15:06:23 2015 +0100
Commit: Ian Campbell <ian.campbell@xxxxxxxxxx>
CommitDate: Thu Aug 13 10:46:48 2015 +0100
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>
Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
tools/libxl/gentest.py | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
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();
--
generated by git-patchbot for /home/xen/git/xen.git#master
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |