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
Prevent a segfault on deref of null typed pointer #769
Conversation
|
👍 |
|
Shouldn't it rather be an exception to dereference an uninitialized pointer? |
|
Possibly but a common use for a pointer is where it's passed to a function to fill and the function returns a status, it is entirely possible that it indicates okay but has no data so doesn't populate the pointer. |
|
But shouldn't you check before dereferencing then? It sounds to me like the extra check wouldn't be very expensive, but debugging a potential programming error where a pointer isn't supposed to be NULL would be much more work. I think I'd be much more comfortable if there was a separate method for "deref but return Int if NULL", and the default deref throwing an exception. |
|
I'm relaxed either way, but it shouldn't segfault whatever, it would be better if there was a Bool coercion on the Pointer to shorten the check if the exception is chosen. |
|
👍 to a better Bool coercer. |
|
Shall I just change this so it throws an exception, and add a Bool? |
|
Yeah, I think |
|
👍 A failure sounds like a good idea :) I'll do that. |
|
Gah, should have rebased against nom :-\ |
| @@ -96,6 +96,19 @@ my class Match is Capture is Cool { | |||
| } | |||
| } | |||
|
|
|||
| multi sub infix:<eqv>(Match:D $a, Match:D $b) { | |||
| [&&] ( | |||
| $a =:= $b, | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can $a =:= $b (container check, right?) be True while $a.to and $b.to are different?
|
@vendethiel that is already in nom afaik, I screwed up the rebase and added these to this PR by mistake - a2188ec is the only pertinent one :) |
a2188ec
to
faaa516
Compare
|
I'm going to do this again (in #888) |
Stops
perl6 -e 'use NativeCall; my $a = Pointer[int32].new; say $a.deref'
Segmentation fault (core dumped)
Some libraries may quite happily not set a passed pointer if there
isn't any data, this just handles it in a nicer way (obviously
one could do what this patch does in the user code.)