mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
tools/libs/stat: use memcpy instead of strncpy in getBridge
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@arm.com> Acked-by: Wei Liu <wl@xen.org>
This commit is contained in:
1 parent
a7952a320c
commit
40fe714ca4
1 file changed
+10
-3
@@ -29,6 +29,7 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <regex.h>
|
||||
#include <xen-tools/libs.h>
|
||||
|
||||
#include "xenstat_priv.h"
|
||||
|
||||
@@ -78,8 +79,14 @@ 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);
|
||||
result[resultLen - 1] = 0;
|
||||
/*
|
||||
* Do not use strncpy to prevent compiler warning with
|
||||
* gcc >= 10.0
|
||||
* If de->d_name is longer then resultLen we truncate it
|
||||
*/
|
||||
memset(result, 0, resultLen);
|
||||
memcpy(result, de->d_name, MIN(strnlen(de->d_name,
|
||||
NAME_MAX),resultLen - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,7 +271,7 @@ int xenstat_collect_networks(xenstat_node * node)
|
||||
{
|
||||
/* Helper variables for parseNetDevLine() function defined above */
|
||||
int i;
|
||||
char line[512] = { 0 }, iface[16] = { 0 }, devBridge[256] = { 0 }, devNoBridge[257] = { 0 };
|
||||
char line[512] = { 0 }, iface[16] = { 0 }, devBridge[16] = { 0 }, devNoBridge[17] = { 0 };
|
||||
unsigned long long rxBytes, rxPackets, rxErrs, rxDrops, txBytes, txPackets, txErrs, txDrops;
|
||||
|
||||
struct priv_data *priv = get_priv_data(node->handle);
|
||||
|
||||