Skip to content

Add nullptr checks before accessing children in getUnspecialized #66644

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

Merged
merged 1 commit into from
Jun 15, 2023

Conversation

augusto2112
Copy link
Contributor

The demangler already has an error mechanism to report if demangling failed. Add null pointer checks before every access in Demangle::getUnspecialized, and return an error if the child doesn't exist.

rdar://110141007

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks!

Copy link
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use DEMANGLER_ASSERT() here, I think, since these nodes are supposed to have children and not having means there's a bug somewhere else in the demangling code.

DEMANGLER_ASSERT() returns a ManglingError in the runtime and in non-asserts builds, but in asserts builds it'll raise an assertion failure, which arguably we'd like to do in this case I think.

e.g. instead of

if (!node->hasChildren())
  return MANGLING_ERROR(ManglingError::BadNominalTypeKind, node);

we could do

DEMANGLER_ASSERT(node->hasChildren(), node);

The demangler already has an error mechanism to report if demangling
failed. Add null pointer checks before every access in
Demangle::getUnspecialized, and return an error if the child doesn't
exist.

rdar://110141007
@augusto2112 augusto2112 force-pushed the null-ptr-children-main branch from 8aaf3c8 to 4e2213d Compare June 15, 2023 19:52
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

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.

3 participants