From c3cb59d6aee0036352d9fe2b89556ea6a2a2d721 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 13 Aug 2021 16:29:22 +0100 Subject: [PATCH] TextEditor: Avoid some potential nullptr dereferences in the Iterator class --- modules/juce_gui_basics/widgets/juce_TextEditor.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp index ef6b8fec1b..ba1153cf80 100644 --- a/modules/juce_gui_basics/widgets/juce_TextEditor.cpp +++ b/modules/juce_gui_basics/widgets/juce_TextEditor.cpp @@ -480,6 +480,9 @@ struct TextEditor::Iterator //============================================================================== void draw (Graphics& g, const UniformTextSection*& lastSection, AffineTransform transform) const { + if (atom == nullptr) + return; + if (passwordCharacter != 0 || (underlineWhitespace || ! atom->isWhitespace())) { if (lastSection != currentSection) @@ -513,6 +516,9 @@ struct TextEditor::Iterator void drawSelectedText (Graphics& g, Range selected, Colour selectedTextColour, AffineTransform transform) const { + if (atom == nullptr) + return; + if (passwordCharacter != 0 || ! atom->isWhitespace()) { GlyphArrangement ga; @@ -548,7 +554,7 @@ struct TextEditor::Iterator //============================================================================== float indexToX (int indexToFind) const { - if (indexToFind <= indexInText) + if (indexToFind <= indexInText || atom == nullptr) return atomX; if (indexToFind >= indexInText + atom->numChars) @@ -567,7 +573,7 @@ struct TextEditor::Iterator int xToIndex (float xToFind) const { - if (xToFind <= atomX || atom->isNewLine()) + if (xToFind <= atomX || atom == nullptr || atom->isNewLine()) return indexInText; if (xToFind >= atomRight)