[Tizen] Error checking when some text relative codes return nullptr 99/320099/2 accepted/tizen/7.0/unified/20250224.165041
authorEunki Hong <eunkiki.hong@samsung.com>
Thu, 17 Oct 2024 00:42:54 +0000 (09:42 +0900)
committerANZ1217 <chihun.jeong@samsung.com>
Mon, 24 Feb 2025 06:20:51 +0000 (15:20 +0900)
1. hyphenation.GetDictionaryEncoding() can return nullptr logically.
   We must doing error check for it.

2. hyphenation.GetWordHyphens() could return empty list if their
   was some error exist at hyphenation. TextUpdate logic must consider it.

3. Some environment values didnt restore as previous value.
   Let we make revert them.

Change-Id: I69fa81f6983de02a8d93566ddc724155dc25c6d4
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringLTR.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopupMirroringRTL.cpp
dali-toolkit/internal/text/controller/text-controller-impl-model-updater.cpp
dali-toolkit/internal/text/hyphenator.cpp

index dce1f802a3883c5c4e5b8bd945e48bf52e31c60b..241dd8169169174f6d42b8ae691829455747f6ec 100644 (file)
@@ -192,7 +192,7 @@ void CreateTextModel(const std::string&                text,
 
       Vector<bool> hyphens = GetWordHyphens(utf32Characters.Begin() + index, wordEnd - index, nullptr);
 
-      for(CharacterIndex i = 0; i < (wordEnd - index); i++)
+      for(CharacterIndex i = 0; i < (wordEnd - index) && i < hyphens.Count(); i++)
       {
         if(hyphens[i])
         {
index 70284e808e1b184aea47373aca108e3572797614..042afe83b117eb4cfab40d2695d0160fc7525340 100644 (file)
@@ -39,10 +39,16 @@ void dali_textselectionpopupmirroringltr_startup(void)
 {
   // Keep the current locale environment.
   char* langPtr = getenv("LANG");
-  gLocaleLang   = std::string(langPtr);
+  if(langPtr)
+  {
+    gLocaleLang = std::string(langPtr);
+  }
 
   char* languagePtr = getenv("LANGUAGE");
-  gLocaleLanguage   = std::string(languagePtr);
+  if(languagePtr)
+  {
+    gLocaleLanguage = std::string(languagePtr);
+  }
 
   // Set the locale environment to Arabic.
   setenv("LANG", "en_GB.UTF-8", 1);
@@ -54,8 +60,22 @@ void dali_textselectionpopupmirroringltr_startup(void)
 void dali_textselectionpopupmirroringltr_cleanup(void)
 {
   // Restore the locale environment.
-  setenv("LANG", gLocaleLang.c_str(), 1);
-  setenv("LANGUAGE", gLocaleLanguage.c_str(), 1);
+  if(gLocaleLang.empty())
+  {
+    unsetenv("LANG");
+  }
+  else
+  {
+    setenv("LANG", gLocaleLang.c_str(), 1);
+  }
+  if(gLocaleLanguage.empty())
+  {
+    unsetenv("LANGUAGE");
+  }
+  else
+  {
+    setenv("LANGUAGE", gLocaleLanguage.c_str(), 1);
+  }
 
   test_return_value = TET_PASS;
 }
index 187de5756414e7a3bdfc99d53c04bebc2040a044..785047cc51f7dc05ff85251dcf002ca58d19ac4d 100644 (file)
@@ -39,10 +39,16 @@ void dali_textselectionpopupmirroringrtl_startup(void)
 {
   // Keep the current locale environment.
   char* langPtr = getenv("LANG");
-  gLocaleLang   = std::string(langPtr);
+  if(langPtr)
+  {
+    gLocaleLang = std::string(langPtr);
+  }
 
   char* languagePtr = getenv("LANGUAGE");
-  gLocaleLanguage   = std::string(languagePtr);
+  if(languagePtr)
+  {
+    gLocaleLanguage = std::string(languagePtr);
+  }
 
   // Set the locale environment to Arabic.
   setenv("LANG", "ar_AE.UTF-8", 1);
@@ -54,8 +60,22 @@ void dali_textselectionpopupmirroringrtl_startup(void)
 void dali_textselectionpopupmirroringrtl_cleanup(void)
 {
   // Restore the locale environment.
-  setenv("LANG", gLocaleLang.c_str(), 1);
-  setenv("LANGUAGE", gLocaleLanguage.c_str(), 1);
+  if(gLocaleLang.empty())
+  {
+    unsetenv("LANG");
+  }
+  else
+  {
+    setenv("LANG", gLocaleLang.c_str(), 1);
+  }
+  if(gLocaleLanguage.empty())
+  {
+    unsetenv("LANGUAGE");
+  }
+  else
+  {
+    setenv("LANGUAGE", gLocaleLanguage.c_str(), 1);
+  }
 
   test_return_value = TET_PASS;
 }
index 3068db5e19f503c2a8d3d1280d3f8228fcf71e9d..4f71ca3674dc7abf7c485a6da54dd5008511a346 100644 (file)
@@ -186,7 +186,7 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
 
         Vector<bool> hyphens = GetWordHyphens(utf32Characters.Begin() + index, wordEnd - index, nullptr);
 
-        for(CharacterIndex i = 0; i < (wordEnd - index); i++)
+        for(CharacterIndex i = 0; i < (wordEnd - index) && i < hyphens.Size(); i++)
         {
           if(hyphens[i])
           {
index 66f99a3671ecf2a6ccea5a87cceea6ce0761d962..9799e1b252b01d4def988ca16ce6cbb2cf709f9c 100644 (file)
@@ -50,7 +50,8 @@ Vector<bool> GetWordHyphens(const Character* word,
 
   // first get the needed encoding
   std::string text;
-  if(strcmp(hyphenation.GetDictionaryEncoding(lang), UTF8) == 0)
+  const char* dictionaryEncodingName = hyphenation.GetDictionaryEncoding(lang);
+  if(DALI_LIKELY(dictionaryEncodingName) && strcmp(dictionaryEncodingName, UTF8) == 0)
   {
     Utf32ToUtf8(word, wordSize, text);
   }