Fixed bad memset, which didn't correctly initialize the hungarian structure
authorMatthias Braun <matze@braunis.de>
Mon, 29 Jan 2007 21:47:42 +0000 (21:47 +0000)
committerMatthias Braun <matze@braunis.de>
Mon, 29 Jan 2007 21:47:42 +0000 (21:47 +0000)
Added an assert to assure costs are >= 0, not sure if that is correct, if it is
not then max_costs should be initialized to INT_MIN...

[r8568]

ir/adt/hungarian.c

index 7d08c43..943567e 100644 (file)
@@ -88,7 +88,7 @@ hungarian_problem_t *hungarian_new(int rows, int cols, int width, int match_type
        int i;
        hungarian_problem_t *p = xmalloc(sizeof(*p));
 
-       memset(p, 0, sizeof(p));
+       memset(p, 0, sizeof(p[0]));
 
        FIRM_DBG_REGISTER(p->dbg, "firm.hungarian");
 
@@ -152,6 +152,7 @@ void hungarian_prepare_cost_matrix(hungarian_problem_t *p, int mode) {
 void hungarian_add(hungarian_problem_t *p, int left, int right, int cost) {
        assert(p->num_rows > left  && "Invalid row selected.");
        assert(p->num_cols > right && "Invalid column selected.");
+       assert(cost >= 0);
 
        p->cost[left][right] = cost;
        p->max_cost          = MAX(p->max_cost, cost);