[cli] fix warning of strncpy (#6992)

Using memcpy seems to be simplest, most efficient way.
This commit is contained in:
Li Cao
2021-09-10 08:36:26 -07:00
committed by GitHub
parent 35e5e20621
commit f329722edb
+3 -2
View File
@@ -533,8 +533,9 @@ otError Coap::ProcessRequest(Arg aArgs[], otCoapCode aCoapCode)
memcpy(&mRequestAddr, &coapDestinationIp, sizeof(mRequestAddr));
mRequestTokenLength = otCoapMessageGetTokenLength(message);
memcpy(mRequestToken, otCoapMessageGetToken(message), mRequestTokenLength);
strncpy(mRequestUri, coapUri, sizeof(mRequestUri) - 1);
mRequestUri[sizeof(mRequestUri) - 1] = '\0'; // Fix gcc-9.2 warning
// Use `memcpy` instead of `strncpy` here because GCC will give warnings for `strncpy` when the dest's length is
// not bigger than the src's length.
memcpy(mRequestUri, coapUri, sizeof(mRequestUri) - 1);
}
#endif