isl_map.c: avoid potential NULL dereference
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 4 Dec 2008 13:13:24 +0000 (14:13 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 14 Dec 2008 11:56:39 +0000 (12:56 +0100)
include/isl_ctx.h.in
isl_map.c

index 070cd53..7aac125 100644 (file)
@@ -68,6 +68,7 @@ struct isl_ctx {
 #define isl_alloc_type(ctx,type)       isl_alloc(ctx,type,sizeof(type))
 #define isl_realloc_type(ctx,ptr,type) isl_realloc(ctx,ptr,type,sizeof(type))
 #define isl_alloc_array(ctx,type,n)    isl_alloc(ctx,type,(n)*sizeof(type))
+#define isl_calloc_array(ctx,type,n)   (type *)calloc(n, sizeof(type))
 #define isl_realloc_array(ctx,ptr,type,n) \
                                    isl_realloc(ctx,ptr,type,(n)*sizeof(type))
 
index ff5f34e..5abfe3b 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -1073,8 +1073,7 @@ static struct isl_basic_map *remove_duplicate_constraints(
 
        size = round_up(4 * (bmap->n_ineq+1) / 3 - 1);
        bits = ffs(size) - 1;
-       index = isl_alloc_array(ctx, isl_int **, size);
-       memset(index, 0, size * sizeof(isl_int **));
+       index = isl_calloc_array(ctx, isl_int **, size);
        if (!index)
                return bmap;
 
@@ -1303,8 +1302,7 @@ static struct isl_basic_map *remove_duplicate_divs(
 
        size = round_up(4 * bmap->n_div / 3 - 1);
        bits = ffs(size) - 1;
-       index = isl_alloc_array(ctx, int, size);
-       memset(index, 0, size * sizeof(int));
+       index = isl_calloc_array(ctx, int, size);
        if (!index)
                return bmap;
        eq = isl_blk_alloc(ctx, 1+total);
@@ -4320,8 +4318,7 @@ static struct isl_basic_set *remove_shifted_constraints(
 
        size = round_up(4 * (context->n_ineq+1) / 3 - 1);
        bits = ffs(size) - 1;
-       index = isl_alloc_array(ctx, isl_int **, size);
-       memset(index, 0, size * sizeof(isl_int **));
+       index = isl_calloc_array(ctx, isl_int **, size);
        if (!index)
                return bset;