Skip to content

Commit

Permalink
OrcLib: Text: StdoutContainerAdapter: fix stdout pipe break on unicode
Browse files Browse the repository at this point in the history
Some unicode characters truncated the stdout redirection.

Ex: libssl-devamd64.txt
  • Loading branch information
fabienfl-orc committed Feb 8, 2024
1 parent efb2900 commit c505034
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/OrcLib/Text/StdoutContainerAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <string>

#include "Text/Iconv.h"

namespace Orc {

// Adapter for a container interface to be usable with Text::Tree and fmt.
Expand All @@ -19,11 +21,21 @@ struct StdoutContainerAdapter
public:
using value_type = T;

StdoutContainerAdapter()
: m_hStdout(GetStdHandle(STD_OUTPUT_HANDLE))
{
}

void flush()
{
Traits::get_std_out<T>() << m_buffer;
m_buffer.clear();
Traits::get_std_out<T>().flush();
if (m_buffer.size())
{
DWORD written = 0;
auto buffer = ToUtf8(m_buffer);
WriteFile(m_hStdout, (void*)buffer.data(), buffer.size(), &written, NULL);
}

FlushFileBuffers(m_hStdout);
}

void push_back(T c)
Expand All @@ -33,7 +45,10 @@ struct StdoutContainerAdapter
Log::Info(Log::Facility::kLogFile, m_buffer);

m_buffer.push_back(c);
Traits::get_std_out<T>() << m_buffer;

DWORD written = 0;
auto buffer = ToUtf8(m_buffer);
WriteFile(m_hStdout, (void*)buffer.data(), buffer.size(), &written, NULL);
m_buffer.clear();
}
else if (c)
Expand All @@ -43,6 +58,7 @@ struct StdoutContainerAdapter
}

private:
HANDLE m_hStdout;
std::basic_string<T> m_buffer;
};

Expand Down

0 comments on commit c505034

Please sign in to comment.