Skip to content

Commit

Permalink
Fix some edge cases in string conversion when BIT7Z_USE_SYSTEM_CODEPAGE
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Oct 7, 2023
1 parent ec7ab5a commit 58273a6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/internal/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#ifdef _WIN32
#ifdef BIT7Z_USE_SYSTEM_CODEPAGE
#define CODEPAGE GetACP()
#define CODEPAGE CP_ACP
#define CODEPAGE_FLAGS 0
#else
#define CODEPAGE CP_UTF8
#define CODEPAGE_FLAGS WC_NO_BEST_FIT_CHARS
#endif
#else
#ifndef BIT7Z_USE_STANDARD_FILESYSTEM
Expand All @@ -44,7 +46,7 @@ auto narrow( const wchar_t* wideString, size_t size ) -> std::string {
}
#ifdef _WIN32
const int narrowStringSize = WideCharToMultiByte( CODEPAGE,
WC_NO_BEST_FIT_CHARS,
CODEPAGE_FLAGS,
wideString,
static_cast< int >( size ),
nullptr,
Expand All @@ -57,7 +59,7 @@ auto narrow( const wchar_t* wideString, size_t size ) -> std::string {

std::string result( narrowStringSize, 0 );
WideCharToMultiByte( CODEPAGE,
WC_NO_BEST_FIT_CHARS,
CODEPAGE_FLAGS,
wideString,
-1,
&result[ 0 ], // NOLINT(readability-container-data-pointer)
Expand Down

0 comments on commit 58273a6

Please sign in to comment.