This PR is an improved version of #29 with fixed result comparison in anagram_return, so that the benchmark terminates with 0 exit code.
The current anagram implementation does indeed exhibit undefined behavior resulting in an infinite loop, since the length calculation in anagram_ReadDict does not account for null-terminators in strings:
As a result, subsequent allocations by anagram_NewWord return portions of heap used by the dict, which are overwritten, leading to an incorrect result in anagram_buffer.
Benchmark with allocation fix by @Gaudeval yields a different value, leading me to believe the present value of char const *answer in anagram_return was obtained by running the flawed benchmark and inspecting the computed value.
This PR is an improved version of #29 with fixed result comparison in
anagram_return
, so that the benchmark terminates with 0 exit code.The current anagram implementation does indeed exhibit undefined behavior resulting in an infinite loop, since the length calculation in
anagram_ReadDict
does not account for null-terminators in strings:https://github.com/tacle/tacle-bench/blob/e747e24f68631a508f6675c925ee3ede8e631d83/bench/sequential/anagram/anagram.c#L303-L305
and the final 0 terminating the dict:
https://github.com/tacle/tacle-bench/blob/e747e24f68631a508f6675c925ee3ede8e631d83/bench/sequential/anagram/anagram.c#L331
As a result, subsequent allocations by
anagram_NewWord
return portions of heap used by the dict, which are overwritten, leading to an incorrect result inanagram_buffer
.Benchmark with allocation fix by @Gaudeval yields a different value, leading me to believe the present value of
char const *answer
inanagram_return
was obtained by running the flawed benchmark and inspecting the computed value.Fixes #28