Commit 1ffdd573 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

[buddy] backport some fixes from upstream

* src/fdd.c, src/imatrix.c, src/kernel.c, src/reorder.c: Here.
parent 2d13fd50
......@@ -143,9 +143,10 @@ int fdd_extdomain(int *dom, int num)
{
fdvaralloc += (num > fdvaralloc) ? num : fdvaralloc;
domain = (Domain*)realloc(domain, sizeof(Domain)*fdvaralloc);
if (domain == NULL)
Domain* tmp_ptr = (Domain*)realloc(domain, sizeof(Domain)*fdvaralloc);
if (tmp_ptr == NULL)
return bdd_error(BDD_MEMORY);
domain = tmp_ptr;
}
}
......@@ -219,9 +220,10 @@ int fdd_overlapdomain(int v1, int v2)
{
fdvaralloc += fdvaralloc;
domain = (Domain*)realloc(domain, sizeof(Domain)*fdvaralloc);
if (domain == NULL)
Domain* tmp_ptr = (Domain*)realloc(domain, sizeof(Domain)*fdvaralloc);
if (tmp_ptr == NULL)
return bdd_error(BDD_MEMORY);
domain = tmp_ptr;
}
d = &domain[fdvarnum];
......
......@@ -46,7 +46,7 @@ imatrix* imatrixNew(int size)
{
imatrix *mtx = NEW(imatrix,1);
int n,m;
if (!mtx)
return NULL;
......@@ -62,6 +62,7 @@ imatrix* imatrixNew(int size)
{
for (m=0 ; m<n ; m++)
free(mtx->rows[m]);
free(mtx->rows);
free(mtx);
return NULL;
}
......@@ -96,7 +97,7 @@ void imatrixFPrint(imatrix *mtx, FILE *ofile)
for (x=0 ; x<mtx->size ; x++)
fprintf(ofile, "%c", x < 26 ? (x+'a') : (x-26)+'A');
fprintf(ofile, "\n");
for (y=0 ; y<mtx->size ; y++)
{
fprintf(ofile, "%2d %c", y, y < 26 ? (y+'a') : (y-26)+'A');
......@@ -141,7 +142,7 @@ void main(void)
imatrixSet(m,0,2);
imatrixSet(m,8,8);
imatrixSet(m,15,15);
imatrixPrint(m);
}
#endif
......
/*========================================================================
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
Copyright (C) 1996-2002, 2015 by Jorn Lind-Nielsen
All rights reserved
Permission is hereby granted, without written agreement and without
......@@ -334,22 +334,25 @@ int bdd_setvarnum(int num)
}
else
{
if (__unlikely((bddvarset =
(BDD*)realloc(bddvarset,sizeof(BDD)*num*2)) == NULL))
BDD* tmp_ptr = (BDD*)realloc(bddvarset,sizeof(BDD)*num*2);
if (__unlikely(tmp_ptr == NULL))
return bdd_error(BDD_MEMORY);
if (__unlikely((bddlevel2var =
(int*)realloc(bddlevel2var,sizeof(int)*(num+1))) == NULL))
bddvarset = tmp_ptr;
int* tmp_ptr2 = (int*)realloc(bddlevel2var,sizeof(int)*(num+1));
if (__unlikely(tmp_ptr2 == NULL))
{
free(bddvarset);
return bdd_error(BDD_MEMORY);
}
if (__unlikely((bddvar2level =
(int*)realloc(bddvar2level,sizeof(int)*(num+1))) == NULL))
bddlevel2var = tmp_ptr2;
tmp_ptr2 = (int*)realloc(bddvar2level,sizeof(int)*(num+1));
if (__unlikely(tmp_ptr2 == NULL))
{
free(bddvarset);
free(bddlevel2var);
return bdd_error(BDD_MEMORY);
}
bddvar2level = tmp_ptr2;
}
if (__likely(bddrefstack != NULL))
......
......@@ -812,7 +812,7 @@ static void addref_rec(int r, char *dep)
if (r < 2)
return;
if (bddnodes[r].refcou == 0)
if (bddnodes[r].refcou == 0 || MARKED(r))
{
bddfreenum--;
......@@ -880,7 +880,10 @@ static int mark_roots(void)
}
if ((extroots=(int*)(malloc(sizeof(int)*extrootsize))) == NULL)
return bdd_error(BDD_MEMORY);
{
free(dep);
return bdd_error(BDD_MEMORY);
}
iactmtx = imatrixNew(bddvarnum);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment