fix compile warning: -Wstringop-truncation / -Wstringop-overflow

This commit is contained in:
Federico Cuello
2018-12-17 00:08:09 +01:00
parent 541a695e2f
commit 4a10fdb2df
2 changed files with 3 additions and 2 deletions

View File

@@ -812,7 +812,8 @@ bool RemoteClient::RequestServerEditQueue(DownloadQueue::EEditAction action, int
char *names = trailingData + textLen + idLength;
for (CString& name : nameList)
{
int len = strlen(name);
// "len" must be less or equal than: "buffer size" - "already used buffer" - "ending \0"
size_t len = strnlen(name, length - (names - trailingData) - 1);
strncpy(names, name, len + 1);
names += len + 1;
}

View File

@@ -47,7 +47,7 @@ TEST_CASE("BString", "[NString][Quick]")
REQUIRE(!strcmp(str2, "0123456789 Hi, Worl"));
BString<20> str3;
strncpy(str3, "Hello, 0123456789 world", str3.Capacity());
memcpy(str3, "Hello, 0123456789 world", str3.Capacity());
str3[str3.Capacity()] = '\0';
REQUIRE(!strcmp(str3, "Hello, 0123456789 w"));