From: Christoph Mallon Date: Fri, 3 Oct 2008 19:15:34 +0000 (+0000) Subject: Fix too short allocations and missing initialisation when allocation/copying vectors... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=22c0657f3fd723daf66167766de8716b3aedc72e;p=libfirm Fix too short allocations and missing initialisation when allocation/copying vectors, simplify. [r22447] --- diff --git a/matrix.c b/matrix.c index f6b535623..3f19844c2 100644 --- a/matrix.c +++ b/matrix.c @@ -1,44 +1,32 @@ -#include "assert.h" +#include +#include #include "pbqp_t.h" #include "matrix.h" pbqp_matrix *pbqp_matrix_alloc(pbqp *pbqp, unsigned rows, unsigned cols) { - pbqp_matrix *mat; - unsigned index; - assert(cols> 0); assert(rows> 0); unsigned length = rows * cols; - mat = obstack_alloc(&pbqp->obstack, sizeof(*mat) + sizeof(num) * (length - 1)); + pbqp_matrix *mat = obstack_alloc(&pbqp->obstack, sizeof(*mat) + sizeof(*mat->entries) * length); assert(mat); mat->cols = cols; mat->rows = rows; - for (index = 0; index < length; ++index) { - mat->entries[index] = 0; - } + memset(mat->entries, 0, sizeof(*mat->entries) * length); return mat; } pbqp_matrix *pbqp_matrix_copy(pbqp *pbqp, pbqp_matrix *m) { - int i; - int len; - pbqp_matrix *copy = obstack_alloc(&pbqp->obstack, sizeof(*copy)); - + unsigned len = m->rows * m->cols; + pbqp_matrix *copy = obstack_copy(&pbqp->obstack, m, sizeof(*copy) + sizeof(*copy->entries) * len); assert(copy); - len = m->rows * m->cols; - - for (i = 0; i < len; ++i) { - copy->entries[i] = m->entries[i]; - } - return copy; }