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 crashes on Windows by replacing ScopedLpwstr with std::wstring. #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

soerlemans
Copy link

After further investigation into #42.
It seems that the crashes have to do with usage of std::unique_ptr itself.
Even using the correct using ScopedLpwstr = std::unique_ptr<WCHAR[], LpwstrDeleter>;.
With accompanying delete[] does not fix the issue, and the issues persist.

So in order to fix the issue instead of using std::unique_ptr<> we use std::string and std::wstring.
As they abstract direct usage of new[] or delete[].
And the issue with std::unique_ptr<> seems to occur from some kind of mismatch between the C++ runtime allocator and the allocator Windows uses.

Other people who use MultiByteToWideChar() generally use std::wstring:
https://stackoverflow.com/questions/14184709/is-this-code-safe-using-wstring-with-multibytetowidechar

I think in order to fix this issue it is better to follow suite since it seems like the most straightforward way to go.

Copy link

codecov bot commented Mar 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.60%. Comparing base (1865e69) to head (1d35426).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #43   +/-   ##
=======================================
  Coverage   77.60%   77.60%           
=======================================
  Files           4        4           
  Lines         250      250           
  Branches       76       76           
=======================================
  Hits          194      194           
  Misses         33       33           
  Partials       23       23           
Flag Coverage Δ
unittests 77.60% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hrantzsch
Copy link
Owner

Thank you for working on this. Do you think you could come up with a test case that reproduces the crash? So far I have not been able to.

While avoiding the ScopedLpwstr construct and just using std::(w)string is certainly desirable, I'm hesitant to make those changes without a clearly reproducible issue.

@soerlemans
Copy link
Author

So I just did some more testing and apparently I accidentally linked to MSVCRTD.lib.
Whilst trying to fix some stuff.
I got a warning in conflicts that I oversaw and that ended up being the underlying issue behind the bug.
Since I working on including this library in a project which uses an SDK, and it conflicted with that.

As for the PR I would still like to see the changes merged.
Or atleast the std::unique_ptr<WCHAR> type changed to std::unique_ptr<WCHAR[]> (as this specialization will automatically use delete[]).
Removing the need for an explicit deleter.

Is there anything I can/should do in order to get the PR merged?

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