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
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)