Fix help printout iterator edge cases

This commit is contained in:
Jack Andersen 2017-11-13 19:35:00 -10:00
parent 6a797097a4
commit da9b2041f1
1 changed files with 5 additions and 6 deletions

View File

@ -117,11 +117,13 @@ private:
while (it != string.end()) while (it != string.end())
{ {
hecl::SystemString::iterator v=it; std::ptrdiff_t v = it - string.begin();
/* copy string until the end of the line is reached */ /* copy string until the end of the line is reached */
for (counter=WRAP_INDENT ; counter < m_lineWidth ; ++counter) for (counter=WRAP_INDENT ; counter < m_lineWidth ; ++counter)
{ {
if (it >= string.end())
return;
if (*it == _S('\n')) if (*it == _S('\n'))
{ {
counter = WRAP_INDENT; counter = WRAP_INDENT;
@ -152,11 +154,8 @@ private:
if (isspace(*k)) if (isspace(*k))
{ {
counter = WRAP_INDENT; counter = WRAP_INDENT;
if (k < v) if (k - string.begin() < v)
{ k = string.insert(it, _S('\n'));
k = it;
string.insert(k, _S('\n'));
}
else else
*k = _S('\n'); *k = _S('\n');
it = k + 1; it = k + 1;