Skip to content
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

Use guaranteed const for associated object key #141

Merged
merged 2 commits into from
May 22, 2024

Conversation

morganchen12
Copy link
Collaborator

From the Foundation docs for -[NSString UTF8String]:

This C string is a pointer to a structure inside the string object, which may have a lifetime shorter than the string object and will certainly not have a longer lifetime. Therefore, you should copy the C string if it needs to be stored outside of the memory context in which you use this property.

Since the inner pointer may have a shorter lifespan than the owning NSString, it shouldn't be used as a constant value. This PR replaces it with the address of the variable, which is guaranteed to be constant during the lifetime of the string constant.

Copy link
Member

@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

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

Nice find! Does it fix any specific failures?

We could roll this into a 7.12.1 along with a fix for #140

cc: @ncooke3

@ncooke3 ncooke3 added this to the GoogleUtilities 8.0.0 milestone Nov 10, 2023
@ncooke3 ncooke3 changed the base branch from main to release-8.0 May 21, 2024 20:07
@ncooke3
Copy link
Member

ncooke3 commented May 22, 2024

Also would be good to have a changelog entry. Doesn't need to be in this PR though.

Copy link
Member

@ncooke3 ncooke3 left a comment

Choose a reason for hiding this comment

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

lgtm. the ci failure is safe to ignore

@ncooke3 ncooke3 merged commit fa584fc into google:release-8.0 May 22, 2024
18 of 19 checks passed
@morganchen12 morganchen12 deleted the mc/assoc branch May 23, 2024 20:59
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