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 "dangling pointer" warning #1268

Merged
merged 1 commit into from
Aug 31, 2023
Merged

Conversation

proski
Copy link
Contributor

@proski proski commented Feb 25, 2023

Move file_status to the function scope so it doesn't go out of scope while file_in_head is pointing to the data it contains.

Move file_status to the function scope so it doesn't go out of scope while
file_in_head is pointing to the data it contains.
@proski
Copy link
Contributor Author

proski commented Feb 25, 2023

This is one of the two warnings reported by gcc 12.2.1 with the -Wall flags. And it's an actual problem. When a variable goes out of scope its memory can be reused so its contents should not be used beyond than point. That is a well known problem in C++ where objects going out of scope call their destructors. But I can imagine it can be problematic in C as well if the compiler allocates stack exactly as written in the code.

@koutcher
Copy link
Collaborator

LGTM, thanks.

@koutcher koutcher merged commit 46df851 into jonas:master Aug 31, 2023
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