oink
oink copied to clipboard
Uninitialized value in _priority
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: https://github.com/trolando/oink/blob/257d0d088361204449c9bb204b457c2042e26cae/src/game.cpp#L276
This is because _priority
is not calloc
ed but malloc
ed here:
https://github.com/trolando/oink/blob/257d0d088361204449c9bb204b457c2042e26cae/src/game.cpp#L127
This should read:
_priority = (int*)calloc(v_allocated, sizeof(int));
(Or better yet, as this is C++:
_priority = new int[v_allocated] {};
)