[GiNaC-list] Potential issue in comparator in test_antipode

Richard B. Kreckel kreckel at in.terlu.de
Mon Jun 6 18:54:50 CEST 2022


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.


More information about the GiNaC-list mailing list