Skip to content

Commit

Permalink
[cli] fix warning of strncpy (openthread#6992)
Browse files Browse the repository at this point in the history
Using memcpy seems to be simplest, most efficient way.
  • Loading branch information
Irving-cl authored Sep 10, 2021
1 parent 35e5e20 commit f329722
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cli/cli_coap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f329722

Please sign in to comment.