]> granicus.if.org Git - icinga2/commitdiff
Fix crash in i2_eval
authorGunnar Beutner <gunnar@beutner.name>
Wed, 23 Sep 2015 07:30:30 +0000 (09:30 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 23 Sep 2015 07:30:30 +0000 (09:30 +0200)
refs #10198

contrib/i2eval/i2tcl.cpp

index 056dd3f7154d819a4de7d76cae38103f65fba6a3..cdc712a6c6c6025564571388cf5dd688de7ddf1c 100644 (file)
@@ -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<String> 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<String> 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();