Potential issue in comparator in test_antipode
Hi, The comparison in `node::operator<` in time_antipode.cpp seems to be missing a dereference operation in return statement: if (!(*vert==*n.vert)) return (vert<n.vert); This causes the comparator to be non-transitive: (gdb) p *keys[5] < *keys[4] $5 = true (gdb) p *keys[4] < *keys[8] $6 = true (gdb) p *keys[5] < *keys[8] $7 = false which violates the strict weak ordering requirements of std::map (https://en.cppreference.com/w/cpp/named_req/Compare). Such violations may in practice result in non-deterministic behavior or crashes. The issue was found with [SortChecker++ tool](https://github.com/yugr/sortcheckxx). Best regards, Yuri Gribov
Hello Yuri, On 6/4/22 09:22, Yuri Gribov wrote:
The comparison in `node::operator<` in time_antipode.cpp seems to be missing a dereference operation in return statement: if (!(*vert==*n.vert)) return (vert<n.vert);
Oh, that's a goof, indeed.
This causes the comparator to be non-transitive: (gdb) p *keys[5] < *keys[4] $5 = true (gdb) p *keys[4] < *keys[8] $6 = true (gdb) p *keys[5] < *keys[8] $7 = false which violates the strict weak ordering requirements of std::map (https://en.cppreference.com/w/cpp/named_req/Compare). Such violations may in practice result in non-deterministic behavior or crashes.
And fixing it also makes it run much faster.
The issue was found with [SortChecker++ tool](https://github.com/yugr/sortcheckxx).
Thank you for running static analyses tools on FOSS! -richy.
participants (2)
-
Richard B. Kreckel
-
Yuri Gribov