Error checking when some text relative codes return nullptr 81/319181/3
authorEunki Hong <eunkiki.hong@samsung.com>
Thu, 17 Oct 2024 00:42:54 +0000 (09:42 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Thu, 17 Oct 2024 02:55:05 +0000 (11:55 +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/async-text/async-text-loader-impl.cpp
dali-toolkit/internal/text/controller/text-controller-impl-model-updater.cpp
dali-toolkit/internal/text/hyphenator.cpp

index 088d5d8026fc9792ed07b8bab6e4fa3f471cccf9..efa834e0617a5579d5385775b46fa632c15bc87f 100644 (file)
@@ -201,7 +201,7 @@ void CreateTextModel(const std::string&                text,
 
       Vector<bool> hyphens = GetWordHyphens(hyphenation, 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 8974f643ded9be59e9c97ce987cb6895d0e28603..c690d7ca9d79631c8eff9f5bb21f3fb465b46bbd 100644 (file)
@@ -327,7 +327,7 @@ void AsyncTextLoader::Update(AsyncTextParameters& parameters)
 
       Vector<bool> hyphens = GetWordHyphens(mModule.GetHyphenation(), 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 3d579e98bd25a4fec5153d7e0aaeee2199d1a14d..a87a8704c02bca9c4ad283b0f7056bc4a1e14450 100644 (file)
@@ -197,7 +197,7 @@ bool ControllerImplModelUpdater::Update(Controller::Impl& impl, OperationsMask o
 
         Vector<bool> hyphens = GetWordHyphens(hyphenation, 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 1550e92227cdce16ab45ef122870e20b1463904a..0045fc011b3885732314b8f732ec1b1b598e92d3 100644 (file)
@@ -48,7 +48,8 @@ Vector<bool> GetWordHyphens(TextAbstraction::Hyphenation& hyphenation,
 
   // 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);
   }