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

Do not pass wstring::c_str() to wstringToString function #8000

Merged

Conversation

dreamer-dead
Copy link
Contributor

It looks that the wstringToString() function can be called with few types of arguments:

  • with constructed std::wstring object
  • with some WCHAR buf[N] buffer that can be casted to const wchar_t * and this is OK
  • with std::wstring("").c_str() pointer and this is the case I am trying to address with this PR

I think that there is no sense to pass a c_str() from a std::wstring object to wstringToString because it will copy the whole string one more time via std::wstring(const wchat_t*) constructor in the end. Also c_str() will always return a zero terminated string and never a nullptr pointer value.

@dreamer-dead dreamer-dead requested review from a team as code owners April 20, 2023 21:08
Copy link
Member

@Smjert Smjert left a comment

Choose a reason for hiding this comment

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

Good catch!

@Smjert Smjert added the Windows label Apr 21, 2023
@Smjert Smjert merged commit 3f54437 into osquery:master Apr 27, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants