-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
null pointers not safety-checked across ABI boundary #22005
Comments
As I see it the source of the issue in the given reproduction is the fact that the Zig interface of the C function is declared as What is the intended scope of this "bug" (now labeled proposal)?
|
I think Zig is behaving correctly and as expected in this case. By default, any function that returns a pointer in C maps semantically to ?* in Zig. It would be correct to use a bare pointer if, for example, the function in C is decorated with |
the bug was that the extern definition was wrong. i opened this issue to propose Zig should verify that assumption (that indeed the way i produced the "expected message" was by changing the definition to given that, its also very easy to take the stance that "i should've written it right the first time" but part of Zig's mantra is enabling maintainable code and its very easy for me to forsee a case where perhaps when the extern definition was first written it was correct but then the C implementation changed without knowing that it was also changing the contract with the respective Zig code, thus causing a user to run into this exact scenario as well. |
I brought up similar safety checks in #21495 and I still support them. The nuclear option would be to completely forbid As I brought up in that issue, there are already lots of places Zig tries to prevent you from creating a |
Clang’s -fsanitize=null behaves as @nektro suggests Zig should - when something is declared to not be nullable in C/C++ but it is actually null, then it reports an error at the line where this happened. Today, Zig’s tooling is less safe than C/C++’s tooling in this case. Debug safety checks exist to verify assertions are correct and help us catch bugs earlier. Instead of a segfault at a memory address wherever the pointer was used most recently, this could (and imo, should) be a panic at the call site of the extern fn. |
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
Expected Behavior
The text was updated successfully, but these errors were encountered: