destination is padded with zeros until a total of num characters have been written to it.
from http://www.cplusplus.com/reference/cstring/strncpy/
Closes #15151
destination is padded with zeros until a total of num characters have been written to it.
from http://www.cplusplus.com/reference/cstring/strncpy/
Closes #15151
and use COMMAND_SIZE rather than calculating it via sizeof.
I prefer the readability and robustness of the existing code -- it seems error-prone to rely on behavior of strncpy that I think many developers may not be familiar with, in particular if that code were changed I could imagine reviewers overlooking the memset() issue.
I think my concern could be addressed by adding a comment above the call to strncpy and ensuring we have a test that would fail if this behavior were broken (is that already the case?).
NACK.
I prefer the current code, too. I see no need to change this. See, this concerns a very small buffer, if ti'd be megabytes of memory and a potential performance impact it might be different.
Edit: note that I've actually seen issues in the wild where clients didn't properly clear the command field and it leaked a bit of memory. Better to be sure than sorry here.
May I replace strncpy with memcpy then? That'd silence a -pedantic warning.
Nah, I'd say, if you contribute, please make changes that fix user-facing issues. This just isn't worth the overhead IMO.