Skip to content

Uninitialized value in _priority #21

@michaelcadilhac

Description

@michaelcadilhac

Valgrind reports:

==2052526== Conditional jump or move depends on uninitialised value(s)
==2052526==    at 0x1B547D: pg::Game::set_priority(int, int) (game.cpp:276)
==2052526==    by 0x1B52EE: pg::Game::init_vertex(int, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (game.cpp:263)
==2052526==    by 0x1B4FD4: pg::Game::init_random_game(int, long, long) (game.cpp:227)
==2052526==    by 0x12329D: main (test_solvers.cpp:405)

This is the offending line:

else if (node < (n_vertices-1) and _priority[node] > _priority[node+1]) is_ordered = false;

This is because _priority is not calloced but malloced here:

_priority = (int*)malloc(sizeof(int[v_allocated]));

This should read:

_priority = (int*)calloc(v_allocated, sizeof(int));

(Or better yet, as this is C++:

_priority = new int[v_allocated] {};

)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions