Skip to content

Commit

Permalink
Fix default param usage in string conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
gix committed Nov 28, 2011
1 parent 36d8ee2 commit 5b5c8f1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Main.cpp
Expand Up @@ -315,7 +315,7 @@ namespace StringCvt

size_t EstimateWideToCodepage(unsigned codepage, wchar_t const* source, size_t sourceSize)
{
return static_cast<size_t>(::WideCharToMultiByte(codepage, 0, source, checked_cast<int>(wcslen_max(source, sourceSize)), nullptr, 0, "?", NULL) + 1);
return static_cast<size_t>(::WideCharToMultiByte(codepage, 0, source, checked_cast<int>(sourceSize), nullptr, 0, "?", NULL) + 1);
}

class AnsiFromWide {
Expand All @@ -324,11 +324,15 @@ namespace StringCvt
AnsiFromWide(AnsiFromWide const& source) : buffer(source.buffer) { }
AnsiFromWide(wchar_t const* source, size_t sourceSize = ~0)
{
if (sourceSize == ~0)
sourceSize = wcslen(source);
Convert(source, sourceSize);
}

void Convert(wchar_t const* source, size_t sourceSize = ~0)
{
if (sourceSize == ~0)
sourceSize = wcslen(source);
size_t size = EstimateWideToCodepage(CP_ACP, source, sourceSize);
buffer.resize(size);
ConvertWideToCodepage(CP_ACP, buffer.data(), size, source, sourceSize);
Expand Down

0 comments on commit 5b5c8f1

Please sign in to comment.