Skip to content

Commit

Permalink
Pass wchar_t* to std::ifstream::open to prevent implicit UTF16->ANSI
Browse files Browse the repository at this point in the history
The previously passed `const std::wstring&` was implicitly converted to an `std::filesystem::path`.
That library is still considered experimental in the used libc++ release, so it should be avoided outright.
Even worse, this version performs an implicit UTF16->ANSI conversion, breaking all efforts of consistent Unicode usage.
  • Loading branch information
ColinFinck committed Oct 18, 2022
1 parent 6d5d527 commit 0d1ea4b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/EnlyzeDbfLib
4 changes: 2 additions & 2 deletions src/EnlyzeS7PLib/src/s7p_device_id_info_parser.cpp
Expand Up @@ -24,7 +24,7 @@ static bool
_FileExists(const std::wstring& wstrFilePath)
{
// libc++'s std::filesystem doesn't build for Windows yet, so we have to use this inefficient approach :(
std::ifstream f(wstrFilePath);
std::ifstream f(wstrFilePath.c_str());
return f.good();
}

Expand Down Expand Up @@ -323,7 +323,7 @@ _ParseResoffAndLinkhrs(std::vector<S7DeviceIdInfo>& DeviceIdInfos, const std::ws

// Open the linkhrs.lnk file.
std::wstring wstrLinkhrsFilePath = wstrS7PFolderPath + L"\\hrs\\linkhrs.lnk";
std::ifstream Linkhrs(wstrLinkhrsFilePath, std::ios::binary);
std::ifstream Linkhrs(wstrLinkhrsFilePath.c_str(), std::ios::binary);
if (!Linkhrs)
{
return CS7PError(L"Could not open linkhrs.lnk");
Expand Down

0 comments on commit 0d1ea4b

Please sign in to comment.