From 33d8d9c5ee22bf755e7bc1d69cc71e1745f9ef39 Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Sun, 21 Feb 2016 15:09:28 +0100 Subject: [PATCH] Avoid zero width in Tbc::Text - causes underflow (and ultimately out_of_range exception) when there are no wrappable characters and substring of width-1 is extracted --- include/external/tbc_text_format.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/external/tbc_text_format.h b/include/external/tbc_text_format.h index a63d6a14..895c34f9 100644 --- a/include/external/tbc_text_format.h +++ b/include/external/tbc_text_format.h @@ -77,9 +77,9 @@ namespace Tbc { pos = remainder.find_last_of( _attr.tabChar, width ); if( pos != std::string::npos ) { tabPos = pos; - if( remainder[width] == '\n' ) + if( width == remainder.size() || remainder[width] == '\n' ) width--; - remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); + remainder.erase( tabPos, 1 ); } if( width == remainder.size() ) { @@ -104,7 +104,7 @@ namespace Tbc { } if( lines.size() == 1 ) indent = _attr.indent; - if( tabPos != std::string::npos ) + if( tabPos < _attr.width - indent ) indent += tabPos; } }