Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug, undefined behavior that resulted in segfault #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

manueldeprada
Copy link

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.

profsmucker and others added 2 commits October 19, 2020 14:05
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants