# HG changeset patch
# User Andrey Skvortsov <andrej.skvortzov@gmail.com>
# Date 1538384698 -10800
# Node ID 00d90ab8a4626d49f813de49650eeb110e9a4332
# Parent  23978e5b039a45b1f062680a7ece507382bc28e0
Fix segmentation fault when last lines in text POUs should be highlighted

diff -r 23978e5b039a -r 00d90ab8a462 editors/TextViewer.py
--- a/editors/TextViewer.py	Sat Sep 29 19:18:50 2018 +0300
+++ b/editors/TextViewer.py	Mon Oct 01 12:04:58 2018 +0300
@@ -963,4 +963,5 @@
                 self.StartStyling(highlight_start_pos, 0xff)
                 self.SetStyling(highlight_end_pos - highlight_start_pos, highlight_type)
                 self.StartStyling(highlight_start_pos, 0x00)
-                self.SetStyling(len(self.Editor.GetText()) - highlight_end_pos, wx.stc.STC_STYLE_DEFAULT)
+                until_end = max(0, len(self.Editor.GetText()) - highlight_end_pos)
+                self.SetStyling(until_end, wx.stc.STC_STYLE_DEFAULT)