diff options
author | Mike Krüger <mikkrg@microsoft.com> | 2019-04-10 10:54:38 +0300 |
---|---|---|
committer | xamarin-jenkins <jo.shields+jenkins@xamarin.com> | 2019-04-12 11:02:19 +0300 |
commit | a49c675b72c6848c0cda0fcc8ac07a55ae014411 (patch) | |
tree | 452ae212c2b21617b6450b554edb6e97d91e94a7 | |
parent | 9b958ffd3fa14c85491bf847a8c3b6ac18dd4d4f (diff) |
Fixes VSTS Bug 844252: ArgumentOutOfRangeException in TextViewMargin.TranslateToUTF8Index
https://devdiv.visualstudio.com/DevDiv/_workitems/edit/844252
-rw-r--r-- | main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs | 4 | ||||
-rw-r--r-- | main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextSegmentMarker.cs | 12 |
2 files changed, 9 insertions, 7 deletions
diff --git a/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs b/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs index 8318f4652e..f367f9eaa5 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/Mono.TextEditor/Gui/TextViewMargin.cs @@ -1513,9 +1513,9 @@ namespace Mono.TextEditor throw new ArgumentNullException (nameof (text)); if (textIndex < 0) - throw new ArgumentOutOfRangeException (nameof (textIndex)); + throw new ArgumentOutOfRangeException (nameof (textIndex), "should be >=0 it was " + textIndex); if (textIndex > text.Length) - throw new ArgumentOutOfRangeException (nameof (textIndex)); + throw new ArgumentOutOfRangeException (nameof (textIndex), $"should be <{text.Length} it was {textIndex}"); if (textIndex < curIndex) { unsafe { diff --git a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextSegmentMarker.cs b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextSegmentMarker.cs index 957ae2c619..ee0aa54c49 100644 --- a/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextSegmentMarker.cs +++ b/main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/TextSegmentMarker.cs @@ -138,7 +138,7 @@ namespace Mono.TextEditor void InternalDraw (int markerStart, int markerEnd, MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos) {
- if (markerStart > markerEnd) + if (markerStart >= markerEnd) return;
var layout = metrics.Layout.Layout; double @from; @@ -147,17 +147,19 @@ namespace Mono.TextEditor @from = startXPos; to = endXPos; } else { - int start = startOffset < markerStart ? markerStart : startOffset; - int end = endOffset < markerEnd ? endOffset : markerEnd; + int start = Math.Max (startOffset, markerStart); + int end = Math.Min (endOffset, markerEnd); int /*lineNr,*/ x_pos; uint curIndex = 0;
uint byteIndex = 0;
- metrics.Layout.TranslateToUTF8Index ((uint)(start - startOffset), ref curIndex, ref byteIndex); + uint idx = (uint)Math.Min (Math.Max (0, start - startOffset), metrics.Layout.Text.Length - 1); + metrics.Layout.TranslateToUTF8Index (idx, ref curIndex, ref byteIndex); x_pos = layout.IndexToPos (System.Math.Max (0, (int)byteIndex)).X; @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
- metrics.Layout.TranslateToUTF8Index ((uint)(end - startOffset), ref curIndex, ref byteIndex); + idx = (uint)Math.Min (Math.Max (0, end - startOffset), metrics.Layout.Text.Length - 1); + metrics.Layout.TranslateToUTF8Index (idx, ref curIndex, ref byteIndex); x_pos = layout.IndexToPos (System.Math.Max (0, (int)byteIndex)).X; |