From 38bdbbbd0d75abad7a8e19965033f7ff2bf5fe11 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 23 Sep 2015 09:30:30 +0200 Subject: [PATCH] Fix crash in i2_eval refs #10198 --- contrib/i2eval/i2tcl.cpp | 54 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/contrib/i2eval/i2tcl.cpp b/contrib/i2eval/i2tcl.cpp index 056dd3f71..cdc712a6c 100644 --- a/contrib/i2eval/i2tcl.cpp +++ b/contrib/i2eval/i2tcl.cpp @@ -133,32 +133,34 @@ char *i2_eval(void *uframe, const char *text, Tcl_Interp *interp) } catch (const ScriptError& ex) { DebugInfo di = ex.GetDebugInfo(); - String text = l_Lines[di.Path]; - - std::vector lines; - boost::algorithm::split(lines, text, boost::is_any_of("\n")); - - for (int i = di.FirstLine; i <= di.LastLine; i++) { - int start, len; - - if (i == di.FirstLine) - start = di.FirstColumn; - else - start = 0; - - if (i == di.LastLine) - len = di.LastColumn - di.FirstColumn + 1; - else - len = lines[i].GetLength(); - - String pathInfo = di.Path; - if (i != 1) - pathInfo += "(" + Convert::ToString(i) + ")"; - pathInfo += ": "; - - msgbuf << pathInfo << lines[i - 1] << "\n"; - msgbuf << String(pathInfo.GetLength(), ' '); - msgbuf << String(start, ' ') << String(len, '^') << "\n"; + if (di.FirstLine != 0) { + String text = l_Lines[di.Path]; + + std::vector lines; + boost::algorithm::split(lines, text, boost::is_any_of("\n")); + + for (int i = di.FirstLine; i <= di.LastLine; i++) { + int start, len; + + if (i == di.FirstLine) + start = di.FirstColumn; + else + start = 0; + + if (i == di.LastLine) + len = di.LastColumn - di.FirstColumn + 1; + else + len = lines[i].GetLength(); + + String pathInfo = di.Path; + if (i != 1) + pathInfo += "(" + Convert::ToString(i) + ")"; + pathInfo += ": "; + + msgbuf << pathInfo << lines[i - 1] << "\n"; + msgbuf << String(pathInfo.GetLength(), ' '); + msgbuf << String(start, ' ') << String(len, '^') << "\n"; + } } msgbuf << ex.what(); -- 2.40.0