-
-
Notifications
You must be signed in to change notification settings - Fork 248
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
Feature request: require explicit casting of any **pointer to void* #1940
Comments
wouldn't requiring |
Imagine two internal dialogues of a person who would have to debug this: Case A:
Case B:
|
It's something that could be added in |
@lerno can you recall from your practice any cases when we need to pass a typed double pointer to In my mind, it could be passing I've just grepped all stdlib for So with this reasoning, possibly it is worth thinking about adding this in normal mode? |
I love writing C, with its all problems, I find them manageable. However, there is one issue which costs me hours of stupid debugging, of code which looks valid and just yesterday passed all tests in the place which today is segfaulting.
The symptoms of this issue are so wild and unpredictable, and may expose themselves in segfaulting, weird value printing, or cascading unpredictable behavior of the all sorts of code which rely on call with this issue. C compiler is never complaining about them, sanitizers are calm, and debuggers show just in the structure data.
Problem definition
I'm talking about passing a pointer of a pointer to a
void*
parameters. Usually it happens after refactoring, where initially we have a struct, which may be initialized locally in the function, but then we decided to refactor the code and pass a pointer to this structure.Output is:
So in the case of my program, it didn't segfaulted, and just printed data. Which is more insane to debug than segfault, because the behavior of the program may become completely unpredictable in absolutely different place.
How c3 is affected
Initially, I caught this problem when I was refactoring
std::io::path::PathWalker
function (same refactoring issue, as above). However, it's very popular with C interop and threads too. Issue is getting worse when we didn't have source code of receiving side of a call (e.g., libc).Proposed solution
void*
is not a double pointer, and if it's the case, the compiler should force explicit cast.PathWalk
andThreadFn
as good candidates) maybe it would be safer to switch toany
instead of void, and let user do explicitanycast
with type check?The text was updated successfully, but these errors were encountered: