diff --git a/src/catch2/internal/catch_textflow.cpp b/src/catch2/internal/catch_textflow.cpp index f8b8e7f4..993e1622 100644 --- a/src/catch2/internal/catch_textflow.cpp +++ b/src/catch2/internal/catch_textflow.cpp @@ -6,6 +6,8 @@ // SPDX-License-Identifier: BSL-1.0 #include + +#include #include #include @@ -41,13 +43,16 @@ namespace Catch { void Column::const_iterator::calcLength() { m_addHyphen = false; - const auto maxLineLength = m_column.m_width - indentSize(); m_parsedTo = m_lineStart; + std::string const& current_line = m_column.m_string; if ( current_line[m_lineStart] == '\n' ) { ++m_parsedTo; } - while ( m_parsedTo < current_line.size() && + + const auto maxLineLength = m_column.m_width - indentSize(); + const auto maxParseTo = std::min(current_line.size(), m_lineStart + maxLineLength); + while ( m_parsedTo < maxParseTo && current_line[m_parsedTo] != '\n' ) { ++m_parsedTo; }