fix bug, undefined behavior that resulted in segfault #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Declaring external int variable as a long results in undefined GCC behavior. This resulted in a segmentation fault when using this variable for a comparison.
Details: size variables are defined as ints:
https://github.com/trec-health-misinfo/Trec_eval_extension/blob/2d4e34c2b4a5d6f0f049ff9296f9b6060c39ba2e/Trec_eval_extension/measures.c#L184
but they were imported as longs:
https://github.com/trec-health-misinfo/Trec_eval_extension/blob/2d4e34c2b4a5d6f0f049ff9296f9b6060c39ba2e/Trec_eval_extension/trec_eval.c#L127
This is undefined behavior. GCC doesn't warn about it and nor does Valgrind, so it was a difficult bug to find. The bug resulted in non-ending loops like the one in
https://github.com/trec-health-misinfo/Trec_eval_extension/blob/2d4e34c2b4a5d6f0f049ff9296f9b6060c39ba2e/Trec_eval_extension/trec_eval.c#L349
which in turn resulted in a segmentation fault.
This was already pointed out in #2 , but the root cause of the bug was not found. Looks like older versions of GCC dealt "in the right way" with this undefined behavior.