tests: Fix a compile warning 04/290104/1 accepted/tizen/unified/20230320.164229 accepted/tizen/unified/20230321.035435
authorSeunghun Lee <shiin.lee@samsung.com>
Thu, 5 Jan 2023 04:45:59 +0000 (13:45 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 20 Mar 2023 07:43:40 +0000 (16:43 +0900)
This silences a follow warning.

[  155s] /usr/include/bits/string_fortified.h:106:34: warning: 'char* __builtin_strncpy(char*,
  const char*, unsigned int)' output truncated before terminating nul copying as many bytes
  from a string as its length [-Wstringop-truncation]
[  155s]   106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
[  155s]       | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[  155s] ../tests/tc_screenshooter.cpp: In function 'void client_registry_cb_global(void*,
  wl_registry*, uint32_t, const char*, uint32_t)':

Change-Id: Ibe959f4fdb0117b4b554558d29d79b50da0a6ed9

tests/tc_screenshooter.cpp

index f2b01f4..f84583d 100644 (file)
@@ -531,25 +531,22 @@ _client_tizen_screenshooter_create_anonymous_file(off_t size)
     static const char tempname[] = "/shooter-XXXXXX";
     const char *path;
     char *name = NULL;
+    size_t name_size;
     int fd = -1;
     int ret = -1;
-    int path_len = 0;
 
     path = getenv("XDG_RUNTIME_DIR");
     if (!path) {
         errno = ENOENT;
         return -1;
     }
-    path_len = strlen(path);
-    if (path_len == 0)
-        return -1;
 
-    name = (char *)malloc(path_len + (int)sizeof(tempname));
+    name_size = strlen(path) + sizeof(tempname);
+    name = (char *)malloc(name_size);
     if (name == NULL)
         return -1;
 
-    strncpy(name, path, path_len);
-    strncat(name, tempname, (int)sizeof(tempname));
+    snprintf(name, name_size, "%s%s", path, tempname);
 
     fd = mkstemp(name);
     if (fd >= 0)