aicenter / ShoDi

0 stars 0 forks source link

Memmory access problem when generating the distance Matrix #3

Closed F-I-D-O closed 4 years ago

neumannjan commented 4 years ago

Certain variables are actually required to be size_t instead of unsigned int, in places such as here.

I believe that this is the core reason for the memory access problem, due to nodes * nodes and i * n + j overflowing unsigned int. Variables that represent "the amount of nodes" can be unsigned int, but nodes * nodes already do have to be size_t. This also means that every variable that represents "the amount of edges" should also be size_t because a complete graph has nodes * nodes amount of edges, which means that in case of unsigned 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 of unsigned int? Even though these variables are not strictly necessary to be size_t in every location, if every such variable was size_t, people working on the project in the future would not fall into this trap.

F-I-D-O commented 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.

neumannjan commented 4 years ago

Fixed in b4ff7a2. The critical line was this in johnson.cpp (wait for the page to scroll to it).

F-I-D-O commented 4 years ago

solved