From da9b2041f1d724c1411aa3cc22a336764061b6e8 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 13 Nov 2017 19:35:00 -1000 Subject: [PATCH] Fix help printout iterator edge cases --- hecl/driver/ToolBase.hpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hecl/driver/ToolBase.hpp b/hecl/driver/ToolBase.hpp index 5f0955f75..3fc8b545c 100644 --- a/hecl/driver/ToolBase.hpp +++ b/hecl/driver/ToolBase.hpp @@ -117,11 +117,13 @@ private: 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 */ for (counter=WRAP_INDENT ; counter < m_lineWidth ; ++counter) { + if (it >= string.end()) + return; if (*it == _S('\n')) { counter = WRAP_INDENT; @@ -152,11 +154,8 @@ private: if (isspace(*k)) { counter = WRAP_INDENT; - if (k < v) - { - k = it; - string.insert(k, _S('\n')); - } + if (k - string.begin() < v) + k = string.insert(it, _S('\n')); else *k = _S('\n'); it = k + 1;