[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 1/2] tools: use memcpy instead of strncpy in getBridge
On 05.10.20 18:02, Bertrand Marquis wrote: Use memcpy in getBridge to prevent gcc warnings about truncated strings. We know that we might truncate it, so the gcc warning here is wrong. Revert previous change changing buffer sizes as bigger buffers are not needed. Signed-off-by: Bertrand Marquis <bertrand.marquis@xxxxxxx> --- tools/libs/stat/xenstat_linux.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c index d2ee6fda64..1db35c604c 100644 --- a/tools/libs/stat/xenstat_linux.c +++ b/tools/libs/stat/xenstat_linux.c @@ -78,7 +78,12 @@ static void getBridge(char *excludeName, char *result, size_t resultLen) sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name);if (access(tmp, F_OK) == 0) {- strncpy(result, de->d_name, resultLen); + /* + * Do not use strncpy to prevent compiler warning with + * gcc >= 10.0 + * If de->d_name is longer then resultLen we truncate it + */ + memcpy(result, de->d_name, resultLen - 1); I think you want min(NAME_MAX, resultLen - 1) for the length. Juergen
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |