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

Fix from_ruby<char const*> to return Ruby String handle directly #98

Merged
merged 1 commit into from
May 4, 2017

Conversation

ryannevell
Copy link
Contributor

#97

Rice::String(x).str() would create a temporary std::string on the stack, and returning a pointer to its data could result in memory corruption when newly malloc'd memory was changed. This change removes the need for that temporary copy, and instead returns a pointer to the underlying Ruby string's memory, which will not be freed until that Ruby object is off of the C/C++ stack and is unreachable by Ruby code.

@jasonroelofs
Copy link
Collaborator

Looks like the test suite is good but failing on Ruby 2.4. I'll get that fixed in another change set.

The current iteration of this method came from 7efbd5c which looking at the change to const char * that may not have been the right thing to change.

I can't think of any reason not to apply this change. Chances are people won't be trying to grab binary data in a const char * from a Ruby String (no knowledge of length), but should instead use a std::string. I'll do some quick testing locally and get this in.

Thanks!

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.

2 participants