From: Ian Jackson Subject: [PATCH] libxc: Fix buffer length for get_suspend_file Date: Tue, 18 Mar 2014 13:54:33 +0000 Message-ID: <1395150873-9397-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xensource.com Cc: Julien Grall , Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org Declaring a formal parameter to have an array type doesn't result in the parameter actually having an array type. The type is "adjusted" to a pointer. (C99 6.9.1(7), 6.7.5.3.) So the use of sizeof in xc_suspend.c:get_suspend_file was wrong. Instead, use the #define. Also get rid of the array parameter, as it is misleading. Newer versions of gcc warn about the erroneous code: xc_suspend.c:39:25: error: argument to 'sizeof' in 'snprintf' call is the same expression as the destination; did you mean to provide an explicit length? [-Werror=sizeof-pointer-memaccess] Reported-By: Julien Grall Signed-off-by: Ian Jackson CC: Ian Campbell CC: Julien Grall --- tools/libxc/xc_suspend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/libxc/xc_suspend.c b/tools/libxc/xc_suspend.c index 84ee139..798eaaa 100644 --- a/tools/libxc/xc_suspend.c +++ b/tools/libxc/xc_suspend.c @@ -36,7 +36,7 @@ static void get_suspend_file(char buf[SUSPEND_FILE_BUFLEN], int domid) { - snprintf(buf, sizeof(buf), SUSPEND_LOCK_FILE, domid); + snprintf(buf, SUSPEND_FILE_BUFLEN, SUSPEND_LOCK_FILE, domid); } static int lock_suspend_event(xc_interface *xch, int domid, int *lockfd) -- 1.7.10.4