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
This commit is contained in:
Mickey Rose 2016-02-21 15:09:28 +01:00
parent 1501339438
commit 33d8d9c5ee

View File

@ -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;
}
}