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

Add null check to string_view #148

Merged
merged 2 commits into from
Oct 29, 2023
Merged

Conversation

Fernthedev
Copy link

There's a chance for undefined behaviour in il2cpp string allocations when the given string is null. This attempts to make it more explicit what should occur.

Copy link
Owner

@sc2ad sc2ad left a comment

Choose a reason for hiding this comment

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

Approved after feedback is addressed

shared/utils/il2cpp-utils.hpp Outdated Show resolved Hide resolved
src/utils/typedefs-wrapper.cpp Outdated Show resolved Hide resolved
src/utils/typedefs-wrapper.cpp Outdated Show resolved Hide resolved
@RedBrumbler
Copy link

Before merging things, I think it's warranted to think about whether a null string view should return a non-null StringW, as in my view this is weird behaviour. I think a null string view should return a null StringW.

For a final decision I would like to see the use case that brought this issue to light, and decide from there

@RedBrumbler
Copy link

as it turns out, the std::string and std::string_view behaviour for a default constructed (null) string view is to produce a valid empty string

image

@sc2ad
Copy link
Owner

sc2ad commented Oct 29, 2023

As shown by your first log line (specifically with a.data()): we see a null string so it's clear there is AN issue with the existing implementation. Converting a string view with a null pointer to a stringw is fundamentally odd, though as you mentioned in C++, an empty (but valid) std::string is made. So, I'm going to merge this impl and we can revise further in the future.

@sc2ad sc2ad merged commit 32107b6 into sc2ad:master Oct 29, 2023
1 check passed
@RedBrumbler
Copy link

yes we do see a null string there, but my point was that the standard library turns that into a valid empty string, I also still think it's weird behaviour but if it's what the standard library does I think we should do the same (as is done by merging this ofc)

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