Fix SEGV in ostream_wrapper

This commit is contained in:
Jesse Beder
2014-03-22 19:15:49 -05:00
parent db82302ed0
commit 396a97050d
3 changed files with 27 additions and 5 deletions

View File

@@ -4,7 +4,12 @@
namespace YAML {
ostream_wrapper::ostream_wrapper()
: m_pStream(0), m_pos(0), m_row(0), m_col(0), m_comment(false) {}
: m_buffer(1, '\0'),
m_pStream(0),
m_pos(0),
m_row(0),
m_col(0),
m_comment(false) {}
ostream_wrapper::ostream_wrapper(std::ostream& stream)
: m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false) {}
@@ -19,8 +24,9 @@ void ostream_wrapper::write(const std::string& str) {
std::copy(str.begin(), str.end(), &m_buffer[m_pos]);
}
for (std::size_t i = 0; i < str.size(); i++)
for (std::size_t i = 0; i < str.size(); i++) {
update_pos(str[i]);
}
}
void ostream_wrapper::write(const char* str, std::size_t size) {
@@ -31,8 +37,9 @@ void ostream_wrapper::write(const char* str, std::size_t size) {
std::copy(str, str + size, &m_buffer[m_pos]);
}
for (std::size_t i = 0; i < size; i++)
for (std::size_t i = 0; i < size; i++) {
update_pos(str[i]);
}
}
void ostream_wrapper::update_pos(char ch) {