Browse Source

Fix possible crash with enormous font sizes and some warnings.

Michael Ragazzon 6 years ago
parent
commit
4fda46ed82

+ 3 - 7
Source/Controls/WidgetTextInput.cpp

@@ -40,7 +40,7 @@ namespace Controls {
 static constexpr float CURSOR_BLINK_TIME = 0.7f;
 
 static bool IsWordCharacter(char c) {
-	return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (c < 0 || c >= 128);
+	return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || ((unsigned char)c >= 128);
 }
 
 WidgetTextInput::WidgetTextInput(ElementFormControl* _parent) : internal_dimensions(0, 0), scroll_offset(0, 0), selection_geometry(_parent), cursor_position(0, 0), cursor_size(0, 0), cursor_geometry(_parent)
@@ -571,10 +571,6 @@ int WidgetTextInput::GetCursorIndex() const
 // Moves the cursor along the current line.
 void WidgetTextInput::MoveCursorHorizontal(CursorMovement movement, bool select)
 {
-	const auto is_nonword_character = [](char c) -> bool {
-		return Core::StringUtilities::IsWhitespace(c) || (c >= '!' && c <= '@');
-	};
-
 	// Whether to seek forward or back to align to utf8 boundaries later.
 	bool seek_forward = false;
 
@@ -772,12 +768,12 @@ void WidgetTextInput::ExpandSelection()
 		p_right = search_right();
 	}
 
-	absolute_cursor_index -= (p_index - p_left);
+	absolute_cursor_index -= int(p_index - p_left);
 	UpdateRelativeCursor();
 	MoveCursorToCharacterBoundaries(false);
 	UpdateSelection(false);
 
-	absolute_cursor_index += (p_right - p_left);
+	absolute_cursor_index += int(p_right - p_left);
 	UpdateRelativeCursor();
 	MoveCursorToCharacterBoundaries(true);
 	UpdateSelection(true);

+ 11 - 6
Source/Core/FontEngineDefault/FontFaceHandleDefault.cpp

@@ -231,14 +231,19 @@ int FontFaceHandleDefault::GenerateString(GeometryList& geometry, const String&
 		else
 			layer_colour = layer->GetColour();
 
+		const int num_textures = layer->GetNumTextures();
+
+		if (num_textures == 0)
+			continue;
+
 		// Resize the geometry list if required.
-		if ((int) geometry.size() < geometry_index + layer->GetNumTextures())
-			geometry.resize(geometry_index + layer->GetNumTextures());
-		
-		RMLUI_ASSERT(!geometry.empty());
+		if ((int)geometry.size() < geometry_index + num_textures)
+			geometry.resize(geometry_index + num_textures);
+
+		RMLUI_ASSERT(geometry_index < (int)geometry.size());
 
 		// Bind the textures to the geometries.
-		for (int i = 0; i < layer->GetNumTextures(); ++i)
+		for (int i = 0; i < num_textures; ++i)
 			geometry[geometry_index + i].SetTexture(layer->GetTexture(i));
 
 		line_width = 0;
@@ -265,7 +270,7 @@ int FontFaceHandleDefault::GenerateString(GeometryList& geometry, const String&
 			prior_character = character;
 		}
 
-		geometry_index += layer->GetNumTextures();
+		geometry_index += num_textures;
 	}
 
 	// Cull any excess geometry from a previous generation.