From 0d5ef6541eabbd3c7d0949ee9b9ad5292b82c3a8 Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Mon, 3 Jan 2022 13:54:03 +0900 Subject: [PATCH] Avoid integer overflow in cursor helper functions Since index is uint, it can causes problems if totalNumberOfCharacters is 0. Change-Id: I3a815474a42ddea9f02ab1e358f7edf8ec0f8dac Signed-off-by: Bowon Ryu --- dali-toolkit/internal/text/cursor-helper-functions.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dali-toolkit/internal/text/cursor-helper-functions.cpp b/dali-toolkit/internal/text/cursor-helper-functions.cpp index 7b08c47..2379bcc 100644 --- a/dali-toolkit/internal/text/cursor-helper-functions.cpp +++ b/dali-toolkit/internal/text/cursor-helper-functions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -485,9 +485,9 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, const GlyphInfo* const glyphInfoBuffer = parameters.visualModel->mGlyphs.Begin(); CharacterIndex index; GlyphMetrics glyphMetrics; - MetricsPtr& metrics = parameters.metrics; - GlyphIndex glyphIndex = 0u; - Length numberOfGlyphs = 0u; + MetricsPtr& metrics = parameters.metrics; + GlyphIndex glyphIndex = 0u; + Length numberOfGlyphs = 0u; if(isLastNewParagraph) { @@ -503,8 +503,12 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, cursorInfo.lineHeight = GetLineHeight(newLine); + index = 0u; const Length totalNumberOfCharacters = parameters.logicalModel->mText.Count(); - index = totalNumberOfCharacters - 1; + if(totalNumberOfCharacters > 0u) + { + index = totalNumberOfCharacters - 1u; + } GetGlyphMetricsFromCharacterIndex(index, glyphInfoBuffer, charactersToGlyphBuffer, glyphsPerCharacterBuffer, metrics, glyphMetrics, glyphIndex, numberOfGlyphs); -- 2.7.4