tools/libxc: Annotate xc_report_error with __attribute__((format))
PATCH 1/1 tools/libxc: Annotate xc_report_error with __attribute__((format))
This helps the compiler spot printf formatting errors.
Fix up all errors discovered.
--- tools/libxc/xc_core.c | 2 +- tools/libxc/xc_domain_restore.c | 6 +++--- tools/libxc/xc_gnttab.c | 2 +- tools/libxc/xc_private.h | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-)
tools/libxc/xc_core.c +1 -1
@@ -497,7 +497,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, ctxt =calloc (sizeof (*ctxt), info.max_vcpu_id +1 );if ( !ctxt ) { -PERROR ("Could not allocate vcpu context array" , domid); +PERROR ("Could not allocate vcpu context array" ); goto out; }
tools/libxc/xc_domain_restore.c +3 -3
@@ -102,7 +102,7 @@ static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx, errno =0 ; }if ( len <=0 ) { -ERROR ("%s failed (read rc: %d, errno: %d)" , __func__, len, errno); +ERROR ("%s failed (read rc: %ld, errno: %d)" , __func__, (long )len, errno);return -1 ; } offset += len;
@@ -443,7 +443,7 @@ static int compat_buffer_qemu(xc_interface *xch, struct restore_ctx *ctx, }if (memcmp (qbuf,"QEVM" ,4 ) ) { -ERROR ("Invalid QEMU magic: 0x%08x" , *(unsigned long *)qbuf); +ERROR ("Invalid QEMU magic: 0x%08x" , *(uint32_t *)qbuf);free (qbuf);return -1 ; }
@@ -1802,7 +1802,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom, }else if (pagebuf.acpi_ioport_location ==0 ) {DBGPRINTF ("Use old firmware ioport from the checkpoint\n" ); }else { -ERROR ("Error, unknow acpi ioport location (%i)" , pagebuf.acpi_ioport_location); +ERROR ("Error, unknow acpi ioport location (%" PRId64")" , pagebuf.acpi_ioport_location); } tdatatmp = tdata;
tools/libxc/xc_gnttab.c +1 -1
@@ -75,7 +75,7 @@ static void *_gnttab_map_table(xc_interface *xch, int domid, int *gnt_num)if ( rc || (query.status != GNTST_okay) ) { -ERROR ("Could not query dom's grant size\n" , domid); +ERROR ("Could not query dom%d's grant size\n" , domid);return NULL ; }
tools/libxc/xc_private.h +2 -1
@@ -93,7 +93,8 @@ struct xc_interface_core {xc_osdep_handle ops_handle;/* opaque data for xc_osdep_ops */ }; -void xc_report_error (xc_interface *xch,int code,const char *fmt, ...); +void xc_report_error (xc_interface *xch,int code,const char *fmt, ...) + __attribute__((format (printf,3 ,4 )));void xc_reportv (xc_interface *xch,xentoollog_logger *lg,xentoollog_level ,int code,const char *fmt,va_list args) __attribute__((format (printf,5 ,0 )));
Signature · 1 line
1.7.10.4
tools/libxc/xc_domain_restore.c static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx, · line 105
Quoted 10 lines · Andrew Cooper
tools/libxc/xc_domain_restore.c +1
-1@@ -102,7 +102,7 @@ static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx, errno =0 ; }if ( len <=0 ) { -ERROR ("%s failed (read rc: %d, errno: %d)" , __func__, len, errno); +ERROR ("%s failed (read rc: %ld, errno: %d)" , __func__, (long )len, errno);
The correct way to print an ssize_t is %zd.
tools/libxc/xc_domain_restore.c static int compat_buffer_qemu(xc_interface *xch, struct restore_ctx *ctx, · line 446
Quoted 9 lines
tools/libxc/xc_domain_restore.c +1
-1return -1 ; } offset += len;@@ -443,7 +443,7 @@ static int compat_buffer_qemu(xc_interface *xch, struct restore_ctx *ctx, }if (memcmp (qbuf,"QEVM" ,4 ) ) { -ERROR ("Invalid QEMU magic: 0x%08x" , *(unsigned long *)qbuf); +ERROR ("Invalid QEMU magic: 0x%08x" , *(uint32_t *)qbuf);
0x%08lx with unsigned long or 0x%PRIx32 with uint32_t, not some hybrid, please. (I thin %..lx is the right answer here)
tools/libxc/xc_domain_restore.c static int compat_buffer_qemu(xc_interface *xch, struct restore_ctx *ctx, · line 449
Quoted 3 lines
tools/libxc/xc_domain_restore.c +0
-0free (qbuf);return -1 ; }
Ian.
Quoted 12 lines · Ian Campbell
tools/libxc/xc_domain_restore.c static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx, · line 105
Quoted 10 lines · Andrew Cooper
tools/libxc/xc_domain_restore.c +1
-1@@ -102,7 +102,7 @@ static ssize_t rdexact(xc_interface *xch, struct restore_ctx *ctx, errno =0 ; }if ( len <=0 ) { -ERROR ("%s failed (read rc: %d, errno: %d)" , __func__, len, errno); +ERROR ("%s failed (read rc: %ld, errno: %d)" , __func__, (long )len, errno);The correct way to print an
ssize_tis %zd.
Odd - I thought I tried that and it failed, but clearly I failed to try it correctly.
Quoted 7 lines
Quoted 7 lines
tools/libxc/xc_domain_restore.c +0
-0return -1 ; } offset += len;@@ -443,7 +443,7 @@ static int compat_buffer_qemu(xc_interface *xch, struct restore_ctx *ctx, }
Quoted 5 lines
tools/libxc/xc_domain_restore.c static int compat_buffer_qemu(xc_interface *xch, struct restore_ctx *ctx, · line 446
Quoted 3 lines
tools/libxc/xc_domain_restore.c +1
-1if (memcmp (qbuf,"QEVM" ,4 ) ) { -ERROR ("Invalid QEMU magic: 0x%08x" , *(unsigned long *)qbuf); +ERROR ("Invalid QEMU magic: 0x%08x" , *(uint32_t *)qbuf);0x%08lx with unsigned long or 0x%PRIx32 with
uint32_t, not some hybrid, please. (I thin %..lx is the right answer here)
qbuf is strictly 4 bytes, as identified in the line above. PRIx32 it is. (I remember deciding on PRIx32 and clearly failed to implement it properly)
v2 on its way.
~Andrew