-
-
Couldn't load subscription status.
- Fork 299
Fix printf segfaults with unassigned interfaces #2375
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 printf segfaults with unassigned interfaces #2375
Conversation
| return self.out_substr((*(fault*)arg.ptr).nameof); | ||
| return self.out_substr((*(fault*)arg.ptr).nameof ?: "<EMPTY-FAULT>"); | ||
| case INTERFACE: | ||
| if (!*(uptr*)arg.ptr) return self.out_substr("<EMPTY-INTERFACE>"); |
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.
| if (!*(uptr*)arg.ptr) return self.out_substr("<EMPTY-INTERFACE>"); | |
| if (!((any*)arg).ptr) return self.out_substr("<EMPTY-INTERFACE>"); |
interfaces are stored as an any so while doing !*(uptr*)arg.ptr will work it's probably better to check it like this. it using a uptr also makes it depend on the fact that the any stores its pointer before its type and would break if that ever changes
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.
Very good observation and suggestion. I will make this change. And to reference your other comment, I think this particular check (once updated) can remain under interface to emit the <EMPTY-INTERFACE> text while an empty ANY TypeKind can simply emit <EMPTY>, so that there's at least a distinction to the empty value.
What do you think?
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.
I don't see any issue with that, I think the distinction would be good.
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.
the same error happens when printing something like (any)(int*)null so maybe the check could be moved to the case ANY check to catch that as well
|
Oops I didn't realize this was a PR. Epic fail. |
|
Ok, so I essentially integrated this in my own PR because I thought this was an issue. 🤪 . Mine just had "(null)" though, so I updated it with (empty-any) and (empty-interface) and (empty-fault) as per this PR. I added unit tests for it as well. |
|
Good find and thank you for taking the time with the PR |
Printing interface-typed variables without an assigned value cause segfaults within the stdlib
std::io::printfunctions. Also, empty fault values, while not really something that will occur, should at least output something when encountered.Feel free to change the text for what's output on empty/null input for these two.
Gives:
After fix: