Closed F-I-D-O closed 4 years ago
I think that if there is a possibility of the overflow of some quantity, we need to extend the type (either to unsigned long or size_t). We need to do it in all places, a quantity (here I understand it as a permutation of two nodes -> count of all potential edges) should have a consistent representation in the program.
Fixed in b4ff7a2. The critical line was this in johnson.cpp
(wait for the page to scroll to it).
solved
Certain variables are actually required to be
size_t
instead ofunsigned int
, in places such as here.I believe that this is the core reason for the memory access problem, due to
nodes * nodes
andi * n + j
overflowingunsigned int
. Variables that represent "the amount of nodes" can beunsigned int
, butnodes * nodes
already do have to besize_t
. This also means that every variable that represents "the amount of edges" should also besize_t
because a complete graph hasnodes * nodes
amount of edges, which means that in case ofunsigned int
, overflow is also possible with such variables.Should I standardize every "amount of nodes" variable (returned by functions / expected as parameters) to be
size_t
instead ofunsigned int
? Even though these variables are not strictly necessary to besize_t
in every location, if every such variable wassize_t
, people working on the project in the future would not fall into this trap.