Skip to content

Conversation

@bryonglodencissp
Copy link

[src/node-boilerplate/scrypt_common.cc:98]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.

What happened in the original version of this code was:

  1. instance of std::string is created - it is an object with automatic storage duration
  2. pointer to the internal memory of this string is returned
  3. object scrypt_err_description is destructed and its' internal memory is cleaned up
  4. the caller of this function receives a dangling pointer (invalid pointer) which yields undefined behavior

The best solution: return an object and call .c_str() on the returned value.

REF: http://stackoverflow.com/questions/22330250/how-to-return-a-stdstring-c-str: How to return a std::string.c_str()

Found by https://github.com/bryongloden/cppcheck

[src/node-boilerplate/scrypt_common.cc:98]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.
@BrandonZacharie
Copy link

I think this may fix #131

@barrysteyn
Copy link
Owner

I'll look into this shortly...

On Aug 16, 2016 10:36 PM, "Brandon Zacharie" notifications@github.com
wrote:

I think this may fix #131
#131


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#133 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABd1RPCEiBCMHLZBaXmok1v37ol0FGRlks5qgp3ggaJpZM4Jic4L
.

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