]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
libxc: Fix buffer length for get_suspend_file
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 18 Mar 2014 13:45:25 +0000 (13:45 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 18 Mar 2014 13:56:47 +0000 (13:56 +0000)
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 size, 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 <julien.grall@linaro.org>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Ian Campbell <ian.campbell@citrix.com>
CC: Julien Grall <julien.grall@linaro.org>
--
v2: Actually change the declaration of buf.

tools/libxc/xc_suspend.c

index 84ee1397d12fd9f98713b44455740ad9ac0fd0a9..200d381d00415b697eea5ed39f28ac4d0db8d137 100644 (file)
@@ -34,9 +34,9 @@
 
 #define SUSPEND_FILE_BUFLEN (sizeof(SUSPEND_LOCK_FILE) + 10)
 
-static void get_suspend_file(char buf[SUSPEND_FILE_BUFLEN], int domid)
+static void get_suspend_file(char buf[], 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)