Fix svace issues 67/283467/4
authorBowon Ryu <bowon.ryu@samsung.com>
Thu, 27 Oct 2022 09:39:56 +0000 (18:39 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Thu, 27 Oct 2022 10:49:48 +0000 (19:49 +0900)
added some castings.

Change-Id: I3faf830d41c3e25211381a768eec1c30e9f67d07
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp
dali-toolkit/internal/text/bidirectional-support.cpp
dali-toolkit/internal/text/controller/text-controller-impl-event-handler.cpp
dali-toolkit/internal/text/controller/text-controller-impl-model-updater.cpp
dali-toolkit/internal/text/controller/text-controller-text-updater.cpp
dali-toolkit/internal/text/layouts/layout-engine-helper-functions.cpp
dali-toolkit/internal/text/logical-model-impl.cpp
dali-toolkit/internal/text/rendering/atlas/atlas-manager-impl.cpp
dali-toolkit/internal/text/rendering/text-typesetter.cpp
dali-toolkit/internal/text/rendering/vector-based/vector-blob-atlas.cpp
dali-toolkit/internal/text/text-geometry.cpp

index 23febac..27a14a9 100644 (file)
@@ -2673,6 +2673,17 @@ int utcDaliTextLabelGeometryOneGlyph(void)
 
   TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
 
+  positionsList.Clear();
+  sizeList.Clear();
+
+  startIndex = 2;
+  endIndex   = 0;
+
+  positionsList = DevelTextLabel::GetTextPosition(label, startIndex, endIndex);
+  sizeList      = DevelTextLabel::GetTextSize(label, startIndex, endIndex);
+
+  TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
+
   END_TEST;
 }
 
index 9bf27f8..b158e7c 100644 (file)
@@ -313,12 +313,12 @@ void GetCharactersDirection(const Vector<BidirectionalParagraphInfoRun>& bidirec
     const Length numberOfLeftToRightCharacters = paragraph.characterRun.characterIndex - index;
     if(numberOfLeftToRightCharacters > 0u)
     {
-      memset(directionsBuffer + index - startIndex, false, numberOfLeftToRightCharacters * sizeof(bool));
+      memset(directionsBuffer + static_cast<std::size_t>(index - startIndex), false, static_cast<std::size_t>(numberOfLeftToRightCharacters) * sizeof(bool));
     }
 
     // Set the directions of the bidirectional text.
     bidirectionalSupport.GetCharactersDirection(paragraph.bidirectionalInfoIndex,
-                                                directionsBuffer + paragraph.characterRun.characterIndex - startIndex,
+                                                directionsBuffer + static_cast<std::size_t>(paragraph.characterRun.characterIndex - startIndex),
                                                 paragraph.characterRun.numberOfCharacters);
 
     // Update the index.
@@ -326,7 +326,7 @@ void GetCharactersDirection(const Vector<BidirectionalParagraphInfoRun>& bidirec
   }
 
   // Fills with left to right those paragraphs without right to left characters.
-  memset(directionsBuffer + index - startIndex, false, (lastCharacter - index) * sizeof(bool));
+  memset(directionsBuffer + static_cast<std::size_t>(index - startIndex), false, static_cast<std::size_t>(lastCharacter - index) * sizeof(bool));
 
   // If the direction info is updated, it needs to be inserted in the model.
   if(updateCurrentBuffer)
index 9dcf07a..e888f74 100644 (file)
@@ -334,7 +334,7 @@ void ControllerImplEventHandler::OnCursorKeyEvent(Controller::Impl& impl, const
 
     const LineIndex lineIndex         = visualModel->GetLineOfCharacter(characterIndex);
     const LineIndex previousLineIndex = (lineIndex > 0 ? lineIndex - 1u : lineIndex);
-    const LineIndex lastLineIndex     = (visualModel->mLines.Size() > 0 ? visualModel->mLines.Size() - 1u : 0);
+    const size_t    lastLineIndex     = (visualModel->mLines.Size() > 0 ? visualModel->mLines.Size() - 1u : 0);
     const bool      isLastLine        = (previousLineIndex == lastLineIndex);
 
     // Retrieve the cursor position info.
@@ -383,7 +383,7 @@ void ControllerImplEventHandler::OnCursorKeyEvent(Controller::Impl& impl, const
       const LineRun& currline = *(visualModel->mLines.Begin() + lineIndex);
 
       // Get last line index
-      const LineIndex lastLineIndex = (visualModel->mLines.Size() > 0 ? visualModel->mLines.Size() - 1u : 0);
+      const size_t    lastLineIndex = (visualModel->mLines.Size() > 0 ? visualModel->mLines.Size() - 1u : 0);
       const bool      isLastLine    = (lineIndex + 1u == lastLineIndex);
 
       // Get the next hit 'y' point.
index 8b6b639..adf1af0 100644 (file)
@@ -330,7 +330,7 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
     updated = true;
   }
 
-  const Length numberOfGlyphs = glyphs.Count() - currentNumberOfGlyphs;
+  const Length numberOfGlyphs = static_cast<Length>(glyphs.Count()) - currentNumberOfGlyphs;
 
   if(Controller::NO_OPERATION != (Controller::GET_GLYPH_METRICS & operations))
   {
index addb91a..ca551eb 100644 (file)
@@ -372,7 +372,7 @@ void Controller::TextUpdater::InsertText(Controller& controller, const std::stri
     {
       pos = modifyText.Begin() + cursorIndex;
     }
-    unsigned int realPos = pos - modifyText.Begin();
+    unsigned int realPos = static_cast<unsigned int>(pos - modifyText.Begin());
     modifyText.Insert(pos, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText);
 
     if(NULL != impl.mEditableControlInterface)
index db2fddf..834ee7f 100644 (file)
@@ -90,7 +90,7 @@ void CalculateGlyphPositionsRTL(const VisualModelPtr&            visualModel,
     const GlyphIndex glyphIndex = *(charactersToGlyphsBuffer + characterVisualIndex);
     const GlyphInfo& glyph      = *(glyphsBuffer + glyphIndex);
 
-    Vector2& position = *(glyphPositionsBuffer + glyphIndex - startGlyphIndex);
+    Vector2& position = *(glyphPositionsBuffer + static_cast<std::size_t>(glyphIndex - startGlyphIndex));
     position.x        = penX;
     position.y        = -glyph.yBearing;
 
@@ -140,7 +140,7 @@ void TraversesCharactersForGlyphPositionsRTL(const VisualModelPtr&  visualModel,
       DALI_ASSERT_DEBUG(glyphIndex < visualModel->mGlyphs.Count());
 
       const GlyphInfo& glyph    = *(glyphsBuffer + glyphIndex);
-      Vector2&         position = *(glyphPositionsBuffer + glyphIndex - startGlyphIndex);
+      Vector2&         position = *(glyphPositionsBuffer + static_cast<std::size_t>(glyphIndex - startGlyphIndex));
 
       position.x = penX + glyph.xBearing;
       position.y = -glyph.yBearing;
index 7ebf2a7..b7274c0 100644 (file)
@@ -146,8 +146,8 @@ CharacterIndex LogicalModel::GetLogicalCursorIndex(CharacterIndex visualCursorIn
     // both characters and the direction of the paragraph.
 
     const CharacterIndex previousVisualCursorIndex  = visualCursorIndex - 1u;
-    const CharacterIndex previousLogicalCursorIndex = *(bidirectionalLineInfo->visualToLogicalMap + previousVisualCursorIndex - bidirectionalLineInfo->characterRun.characterIndex) + bidirectionalLineInfo->characterRun.characterIndex;
-    const CharacterIndex currentLogicalCursorIndex  = *(bidirectionalLineInfo->visualToLogicalMap + visualCursorIndex - bidirectionalLineInfo->characterRun.characterIndex) + bidirectionalLineInfo->characterRun.characterIndex;
+    const CharacterIndex previousLogicalCursorIndex = *(bidirectionalLineInfo->visualToLogicalMap + static_cast<std::size_t>(previousVisualCursorIndex - bidirectionalLineInfo->characterRun.characterIndex)) + bidirectionalLineInfo->characterRun.characterIndex;
+    const CharacterIndex currentLogicalCursorIndex  = *(bidirectionalLineInfo->visualToLogicalMap + static_cast<std::size_t>(visualCursorIndex - bidirectionalLineInfo->characterRun.characterIndex)) + bidirectionalLineInfo->characterRun.characterIndex;
 
     const CharacterDirection previousCharacterDirection = *(modelCharacterDirections + previousLogicalCursorIndex);
     const CharacterDirection currentCharacterDirection  = *(modelCharacterDirections + currentLogicalCursorIndex);
@@ -199,7 +199,7 @@ CharacterIndex LogicalModel::GetLogicalCharacterIndex(CharacterIndex visualChara
   // The bidirectional line info.
   const BidirectionalLineInfoRun* const bidirectionalLineInfo = mBidirectionalLineInfo.Begin() + mBidirectionalLineIndex;
 
-  return *(bidirectionalLineInfo->visualToLogicalMap + visualCharacterIndex - bidirectionalLineInfo->characterRun.characterIndex) + bidirectionalLineInfo->characterRun.characterIndex;
+  return *(bidirectionalLineInfo->visualToLogicalMap + static_cast<std::size_t>(visualCharacterIndex - bidirectionalLineInfo->characterRun.characterIndex)) + bidirectionalLineInfo->characterRun.characterIndex;
 }
 
 bool LogicalModel::FetchBidirectionalLineInfo(CharacterIndex characterIndex)
@@ -543,7 +543,7 @@ void LogicalModel::CreateParagraphInfo(CharacterIndex startIndex,
   if(updateCurrentParagraphs)
   {
     for(Vector<ParagraphRun>::ConstIterator it    = mParagraphInfo.Begin(),
-                                            endIt = mParagraphInfo.Begin() + totalNumberOfParagraphs - numberOfNewParagraphs;
+                                            endIt = mParagraphInfo.Begin() + static_cast<std::size_t>(totalNumberOfParagraphs - numberOfNewParagraphs);
         it != endIt;
         ++it)
     {
index 8745db1..0308691 100644 (file)
@@ -240,7 +240,7 @@ AtlasManager::SizeType AtlasManager::CheckAtlas(SizeType      atlas,
   {
     // Check to see if the image will fit in these blocks
 
-    const SizeType availableBlocks = mAtlasList[atlas].mAvailableBlocks + mAtlasList[atlas].mFreeBlocksList.Size();
+    const SizeType availableBlocks = mAtlasList[atlas].mAvailableBlocks + static_cast<SizeType>(mAtlasList[atlas].mFreeBlocksList.Size());
 
     if(availableBlocks && IsBlockSizeSufficient(width, height, mAtlasList[atlas].mSize.mBlockWidth, mAtlasList[atlas].mSize.mBlockHeight))
     {
@@ -454,7 +454,7 @@ void AtlasManager::GetMetrics(Toolkit::AtlasManager::Metrics& metrics)
   {
     entry.mSize        = mAtlasList[i].mSize;
     entry.mTotalBlocks = mAtlasList[i].mTotalBlocks;
-    entry.mBlocksUsed  = entry.mTotalBlocks - mAtlasList[i].mAvailableBlocks + mAtlasList[i].mFreeBlocksList.Size();
+    entry.mBlocksUsed  = entry.mTotalBlocks - mAtlasList[i].mAvailableBlocks + static_cast<SizeType>(mAtlasList[i].mFreeBlocksList.Size());
     entry.mPixelFormat = GetPixelFormat(i + 1);
 
     metrics.mAtlasMetrics.PushBack(entry);
index 467b80e..73ae2c5 100644 (file)
@@ -749,12 +749,12 @@ inline Devel::PixelBuffer CreateTransparentImageBuffer(const uint32_t bufferWidt
   if(Pixel::RGBA8888 == pixelFormat)
   {
     const uint32_t bufferSizeInt  = bufferWidth * bufferHeight;
-    const uint32_t bufferSizeChar = sizeof(uint32_t) * bufferSizeInt;
+    const size_t bufferSizeChar = sizeof(uint32_t) * static_cast<std::size_t>(bufferSizeInt);
     memset(imageBuffer.GetBuffer(), 0, bufferSizeChar);
   }
   else
   {
-    memset(imageBuffer.GetBuffer(), 0, bufferWidth * bufferHeight);
+    memset(imageBuffer.GetBuffer(), 0, static_cast<std::size_t>(bufferWidth * bufferHeight));
   }
 
   return imageBuffer;
@@ -945,7 +945,7 @@ PixelData Typesetter::Render(const Vector2& size, Toolkit::DevelText::TextDirect
   const uint32_t bufferHeight = static_cast<uint32_t>(size.height);
 
   const uint32_t bufferSizeInt  = bufferWidth * bufferHeight;
-  const uint32_t bufferSizeChar = sizeof(uint32_t) * bufferSizeInt;
+  const size_t bufferSizeChar = sizeof(uint32_t) * static_cast<std::size_t>(bufferSizeInt);
 
   //Elided text in ellipsis at START could start on index greater than 0
   auto startIndexOfGlyphs = mModel->GetStartIndexOfElidedGlyphs();
index 0f11c11..d71b641 100644 (file)
@@ -188,7 +188,7 @@ void VectorBlobAtlas::TexSubImage(unsigned int offsetX,
                                   unsigned int height,
                                   VectorBlob*  blob)
 {
-  const size_t size   = width * height * 4;
+  const size_t size   = static_cast<size_t>(width) * static_cast<size_t>(height) * 4;
   uint8_t*     pixbuf = new uint8_t[size];
 
   size_t pos;
index 6f173cb..1efae75 100644 (file)
@@ -84,12 +84,12 @@ void GetTextGeometry(ModelPtr textModel, CharacterIndex startIndex, CharacterInd
 
   if(startIndex >= logicalModel->mText.Count())
   {
-    startIndex = logicalModel->mText.Count() - 1;
+    startIndex = static_cast<CharacterIndex>(logicalModel->mText.Count() - 1u);
   }
 
   if(endIndex >= logicalModel->mText.Count())
   {
-    endIndex = logicalModel->mText.Count() - 1;
+    endIndex = static_cast<CharacterIndex>(logicalModel->mText.Count() - 1u);
   }
 
   if(startIndex > endIndex)