From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS387-00062h-MI for qemu-devel@nongnu.org; Wed, 09 May 2012 05:24:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SS384-000283-7W for qemu-devel@nongnu.org; Wed, 09 May 2012 05:24:19 -0400 Received: from mx.meyering.net ([88.168.87.75]:36915) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS383-000241-Vm for qemu-devel@nongnu.org; Wed, 09 May 2012 05:24:16 -0400 From: Jim Meyering Date: Wed, 9 May 2012 11:24:00 +0200 Message-Id: <1336555446-20180-17-git-send-email-jim@meyering.net> In-Reply-To: <1336555446-20180-1-git-send-email-jim@meyering.net> References: <1336555446-20180-1-git-send-email-jim@meyering.net> Subject: [Qemu-devel] [PATCH 16/22] qemu-ga: prefer pstrcpy: consistently NUL-terminate ifreq.ifr_name List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Jim Meyering , Michal Privoznik , Michael Roth , Luiz Capitulino From: Jim Meyering NUL-termination of the .ifr_name field is not required, but is fine (and preferable to using strncpy and leaving the reader to wonder), since the first thing the linux kernel does is to clear the last byte. Besides, using pstrcpy here makes this setting of ifr_name consistent with the other code (e.g., net/tap-linux.c) that does the same thing. Signed-off-by: Jim Meyering --- qga/commands-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index d58730a..7112984 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -786,7 +786,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) } memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, info->value->name, IF_NAMESIZE); + pstrcpy(ifr.ifr_name, IF_NAMESIZE, info->value->name); if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { snprintf(err_msg, sizeof(err_msg), "failed to get MAC addres of %s: %s", -- 1.7.10.1.487.ga3935e6