Skip to content

Fix "dangling pointer" warning#1268

Merged
koutcher merged 1 commit intojonas:masterfrom
proski:dangling-pointer
Aug 31, 2023
Merged

Fix "dangling pointer" warning#1268
koutcher merged 1 commit intojonas:masterfrom
proski:dangling-pointer

Conversation

@proski
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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