Fix compile warning for gcc-14 + Clean application wrap code 86/319486/1
authorEunki Hong <eunkiki.hong@samsung.com>
Tue, 11 Feb 2025 16:14:30 +0000 (01:14 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Tue, 11 Feb 2025 16:18:28 +0000 (01:18 +0900)
1. Let we use memcpy instead of strncpy, to remove [-Wstringop-truncation]
 - Since we can assume that last string is null-terminated, we can skip this warning

2. Remove duplicated codes, and use GenerationArgV for application constuctors.

3. Remove some possible cases to nullptr constructor for std::string

Change-Id: I22baee82bae05fcc4087431730c6386fa74f52b2
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
dali-csharp-binder/dali-adaptor/application-wrap.cpp
dali-csharp-binder/dali-adaptor/component-application-wrap.cpp
dali-csharp-binder/dali-adaptor/dali-adaptor-wrap.cpp
dali-csharp-binder/dali-adaptor/watch-wrap.cpp

index 8addc5f8e66d4f9787b742c9cb8efa940d09887b..1163d49e868ba55f34a1611240a567fd939e0d8c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -18,6 +18,7 @@
 // EXTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/application-devel.h>
 #include <dali/integration-api/adaptor-framework/adaptor.h>
+#include <dali/integration-api/debug.h>
 #include <dali/public-api/adaptor-framework/application.h>
 #include <dali/public-api/adaptor-framework/window-enumerations.h>
 
@@ -54,6 +55,14 @@ void GenerationArgV(int argc, char* argv)
 {
   // TODO : What should we do if already generated argv exist?
   ReleaseArgVMemory();
+
+  // Avoid error case when argc is negative.
+  if(argc < 0)
+  {
+    DALI_LOG_ERROR("[ERROR!] Invalid argc value comes! argc : %d, argv : %p\n", argc, argv);
+    argc = 0;
+  }
+
   // generate argv data from the C# args
   int   index  = 0;
   int   length = 0;
@@ -62,16 +71,19 @@ void GenerationArgV(int argc, char* argv)
 
   gArgV = new char*[argc + 1];
 
-  for(retPtr = strtok_r(argv, " ", &nextPtr);
-      retPtr != NULL && index < argc;
-      retPtr = strtok_r(NULL, " ", &nextPtr))
+  if(argv != NULL)
   {
-    length       = 0;
-    length       = strlen(retPtr);
-    gArgV[index] = new char[length + 1];
-    strncpy(gArgV[index], retPtr, length);
-    gArgV[index][length] = '\0';
-    index++;
+    for(retPtr = strtok_r(argv, " ", &nextPtr);
+        retPtr != NULL && index < argc;
+        retPtr = strtok_r(NULL, " ", &nextPtr))
+    {
+      length       = 0;
+      length       = strlen(retPtr);
+      gArgV[index] = new char[length + 1];
+      memcpy(gArgV[index], retPtr, length);
+      gArgV[index][length] = '\0';
+      index++;
+    }
   }
 
   while(index < argc)
@@ -292,7 +304,7 @@ SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Application_New__SWIG_3(int jarg1, char
   return jresult;
 }
 
-SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Application_New__MANUAL_4(int jarg1, char* jarg2, char* jarg3, int jarg4)
+SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Application_New__MANUAL_4(int nuiArgc, char* nuiArgv, char* jarg3, int jarg4)
 {
   void*                          jresult;
   int*                           argc = nullptr;
@@ -300,42 +312,11 @@ SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Application_New__MANUAL_4(int jarg1, ch
   Dali::Application::WINDOW_MODE arg4;
   Dali::Application              result;
 
-  {
-    // TODO : What should we do if already generated argv exist?
-    ReleaseArgVMemory();
-    // generate argv data from the C# args
-    int   index  = 0;
-    int   length = 0;
-    char* retPtr = NULL;
-    char* nextPtr;
-
-    gArgV = new char*[jarg1 + 1];
+  GUARD_ON_NULL_RET0(jarg3);
 
-    for(retPtr = strtok_r(jarg2, " ", &nextPtr);
-        retPtr != NULL && index < jarg1;
-        retPtr = strtok_r(NULL, " ", &nextPtr))
-    {
-      length       = 0;
-      length       = strlen(retPtr);
-      gArgV[index] = new char[length + 1];
-      strncpy(gArgV[index], retPtr, length);
-      gArgV[index][length] = '\0';
-      index++;
-    }
-
-    while(index < jarg1)
-    {
-      //if jarg1 - index >1, maybe cause error.
-      gArgV[index] = NULL;
-      index++;
-    }
-
-    gArgV[jarg1] = NULL;
-    gArgC        = jarg1;
-
-    argc = &gArgC;
-    argv = &gArgV;
-  }
+  GenerationArgV(nuiArgc, nuiArgv);
+  argc = &gArgC;
+  argv = &gArgV;
 
   std::string arg3(jarg3);
   arg4 = (Dali::Application::WINDOW_MODE)jarg4;
@@ -1697,7 +1678,7 @@ SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Application_New__SWIG_6(int nuiArgc, ch
   return jresult;
 }
 
-SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Application_New_WithWindowSizePosition(int jarg1, char* jarg2, char* jarg3, int jarg4, void* jarg5)
+SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Application_New_WithWindowSizePosition(int nuiArgc, char* nuiArgv, char* jarg3, int jarg4, void* jarg5)
 {
   void*                          jresult;
   int*                           argc = nullptr;
@@ -1707,42 +1688,11 @@ SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Application_New_WithWindowSizePosition(
   Dali::PositionSize*            argp5;
   Dali::Application              result;
 
-  {
-    // TODO : What should we do if already generated argv exist?
-    ReleaseArgVMemory();
-    // generate argv data from the C# args
-    int   index  = 0;
-    int   length = 0;
-    char* retPtr = NULL;
-    char* nextPtr;
-
-    gArgV = new char*[jarg1 + 1];
-
-    for(retPtr = strtok_r(jarg2, " ", &nextPtr);
-        retPtr != NULL && index < jarg1;
-        retPtr = strtok_r(NULL, " ", &nextPtr))
-    {
-      length       = 0;
-      length       = strlen(retPtr);
-      gArgV[index] = new char[length + 1];
-      strncpy(gArgV[index], retPtr, length);
-      gArgV[index][length] = '\0';
-      index++;
-    }
-
-    while(index < jarg1)
-    {
-      //if jarg1 - index >1, maybe cause error.
-      gArgV[index] = NULL;
-      index++;
-    }
-
-    gArgV[jarg1] = NULL;
-    gArgC        = jarg1;
+  GUARD_ON_NULL_RET0(jarg3);
 
-    argc = &gArgC;
-    argv = &gArgV;
-  }
+  GenerationArgV(nuiArgc, nuiArgv);
+  argc = &gArgC;
+  argv = &gArgV;
 
   std::string arg3(jarg3);
   arg4  = (Dali::Application::WINDOW_MODE)jarg4;
@@ -1772,42 +1722,9 @@ SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_Application_New_WithWindowData(int nuiA
   Dali::WindowData* pWindowData;
   Dali::Application result;
 
-  {
-    // TODO : What should we do if already generated argv exist?
-    ReleaseArgVMemory();
-    // generate argv data from the C# args
-    int   index  = 0;
-    int   length = 0;
-    char* retPtr = NULL;
-    char* nextPtr;
-
-    gArgV = new char*[nuiArgc + 1];
-
-    for(retPtr = strtok_r(nuiArgv, " ", &nextPtr);
-        retPtr != NULL && index < nuiArgc;
-        retPtr = strtok_r(NULL, " ", &nextPtr))
-    {
-      length       = 0;
-      length       = strlen(retPtr);
-      gArgV[index] = new char[length + 1];
-      strncpy(gArgV[index], retPtr, length);
-      gArgV[index][length] = '\0';
-      index++;
-    }
-
-    while(index < nuiArgc)
-    {
-      // if nuiArgc - index >1, maybe cause error.
-      gArgV[index] = NULL;
-      index++;
-    }
-
-    gArgV[nuiArgc] = NULL;
-    gArgC          = nuiArgc;
-
-    argc = &gArgC;
-    argv = &gArgV;
-  }
+  GenerationArgV(nuiArgc, nuiArgv);
+  argc = &gArgC;
+  argv = &gArgV;
 
   std::string styleSheet(nuiStyleSheet);
   pWindowData = (Dali::WindowData*)nuiWindowData;
index 2d6454befc4993a54d95b9a4055bee2c178b74d2..2fdcdbc982668a6121b0e4c8f1e815b06e296214 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.\r
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -59,7 +59,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_new_ComponentApplication(int jarg1, ch
     argV[index] = new char[length + 1];\r
     if( retPtr )\r
     {\r
-      strncpy(argV[index], retPtr, length);\r
+      memcpy(argV[index], retPtr, length);\r
     }\r
     argV[index][length] = '\0';\r
     index++;\r
@@ -75,7 +75,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_new_ComponentApplication(int jarg1, ch
       argV[index] = new char[length + 1];\r
       if( retPtr )\r
       {\r
-        strncpy(argV[index], retPtr, length);\r
+        memcpy(argV[index], retPtr, length);\r
       }\r
       argV[index][length] = '\0';\r
       index++;\r
index 69e01f5b42bf96b3fdbcd3c85c01f2f59bd57612..05243bf9226159497e69597121619ad9f820a4d2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -1528,7 +1528,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_WidgetApplication_New(int jarg1, char
     argWidgetV[index] = new char[length + 1];
     if( retPtr )
     {
-      strncpy(argWidgetV[index], retPtr, length);
+      memcpy(argWidgetV[index], retPtr, length);
     }
     argWidgetV[index][length] = '\0';
     index++;
@@ -1544,7 +1544,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_WidgetApplication_New(int jarg1, char
       argWidgetV[index] = new char[length + 1];
       if( retPtr )
       {
-        strncpy(argWidgetV[index], retPtr, length);
+        memcpy(argWidgetV[index], retPtr, length);
       }
       argWidgetV[index][length] = '\0';
       index++;
index b776d36c1c6e39866a330a16d670616290c71d66..e00b238e12bfa1901a977ff31ea8482ae70f559a 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -338,7 +338,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_WatchApplication_New__SWIG_1(int jarg1
     argWatchV[index] = new char[length + 1];
     if( retPtr )
     {
-      strncpy(argWatchV[index], retPtr, length);
+      memcpy(argWatchV[index], retPtr, length);
     }
     argWatchV[index][length] = '\0';
     index++;
@@ -354,7 +354,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_WatchApplication_New__SWIG_1(int jarg1
       argWatchV[index] = new char[length + 1];
       if( retPtr )
       {
-        strncpy(argWatchV[index], retPtr, length);
+        memcpy(argWatchV[index], retPtr, length);
       }
       argWatchV[index][length] = '\0';
       index++;
@@ -397,7 +397,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_WatchApplication_New__SWIG_2(int jarg1
     argWatchV[index] = new char[length + 1];
     if( retPtr )
     {
-      strncpy(argWatchV[index], retPtr, length);
+      memcpy(argWatchV[index], retPtr, length);
     }
     argWatchV[index][length] = '\0';
     index++;
@@ -413,7 +413,7 @@ SWIGEXPORT void * SWIGSTDCALL CSharp_Dali_WatchApplication_New__SWIG_2(int jarg1
       argWatchV[index] = new char[length + 1];
       if( retPtr )
       {
-        strncpy(argWatchV[index], retPtr, length);
+        memcpy(argWatchV[index], retPtr, length);
       }
       argWatchV[index][length] = '\0';
       index++;