From d302f1e193f631abb1c17253e8e3558f9c4a528c Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Sat, 7 Nov 2009 21:19:42 +0000 Subject: [PATCH] Add printf format checks to the cache manager Add printf format checking to the afs_warn and afs_warnuser functions and fix the fallout. Change-Id: I81ed776308a31706bf307246c470ee409797f044 Reviewed-on: http://gerrit.openafs.org/792 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/afs/afs_memcache.c | 4 ++-- src/afs/afs_prototypes.h | 6 ++++-- src/afs/afs_util.c | 18 +++++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/afs/afs_memcache.c b/src/afs/afs_memcache.c index 90e3f8fad4..d2a063b9e6 100644 --- a/src/afs/afs_memcache.c +++ b/src/afs/afs_memcache.c @@ -243,8 +243,8 @@ afs_MemWriteUIO(afs_dcache_id_t *ainode, struct uio *uioP) if (mceP->data == NULL) { /* no available memory */ mceP->data = oldData; /* revert back change that was made */ ReleaseWriteLock(&mceP->afs_memLock); - afs_warn("afs: afs_MemWriteBlk mem alloc failure (%d bytes)\n", - AFS_UIO_RESID(uioP) + AFS_UIO_OFFSET(uioP)); + afs_warn("afs: afs_MemWriteBlk mem alloc failure (%ld bytes)\n", + (long)(AFS_UIO_RESID(uioP) + AFS_UIO_OFFSET(uioP))); return -ENOMEM; } diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index 9c849833a7..fe9a2cc68c 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -965,8 +965,10 @@ extern afs_int32 afs_data_pointer_to_int32(const void *p); extern void afs_warn(); extern void afs_warnuser(); #else -extern void afs_warn(char *fmt, ...); -extern void afs_warnuser(char *fmt, ...); +extern void afs_warn(char *fmt, ...) + AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2); +extern void afs_warnuser(char *fmt, ...) + AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2); #endif /* afs_vcache.c */ diff --git a/src/afs/afs_util.c b/src/afs/afs_util.c index 9855008d0e..c64fc09f45 100644 --- a/src/afs/afs_util.c +++ b/src/afs/afs_util.c @@ -206,7 +206,7 @@ afs_CheckLocks(void) register int i; afs_warn("Looking for locked data structures.\n"); - afs_warn("conn %lx, volume %lx, user %lx, cell %lx, server %lx\n", &afs_xconn, + afs_warn("conn %p, volume %p, user %p, cell %p, server %p\n", &afs_xconn, &afs_xvolume, &afs_xuser, &afs_xcell, &afs_xserver); { register struct vcache *tvc; @@ -220,9 +220,9 @@ afs_CheckLocks(void) #else if (VREFCOUNT(tvc)) #endif - afs_warn("Stat cache entry at %x is held\n", tvc); + afs_warn("Stat cache entry at %p is held\n", tvc); if (CheckLock(&tvc->lock)) - afs_warn("Stat entry at %x is locked\n", tvc); + afs_warn("Stat entry at %p is locked\n", tvc); } } } @@ -232,10 +232,10 @@ afs_CheckLocks(void) tdc = afs_indexTable[i]; if (tdc) { if (tdc->refCount) - afs_warn("Disk entry %d at %x is held\n", i, tdc); + afs_warn("Disk entry %d at %p is held\n", i, tdc); } if (afs_indexFlags[i] & IFDataMod) - afs_warn("Disk entry %d at %x has IFDataMod flag set.\n", i, + afs_warn("Disk entry %d at %p has IFDataMod flag set.\n", i, tdc); } } @@ -246,11 +246,11 @@ afs_CheckLocks(void) for (i = 0; i < NSERVERS; i++) { for (ts = afs_servers[i]; ts; ts = ts->next) { if (ts->flags & SRVR_ISDOWN) - printf("Server entry %lx is marked down\n", (unsigned long)ts); + printf("Server entry %p is marked down\n", ts); for (sa = ts->addr; sa; sa = sa->next_sa) { for (tc = sa->conns; tc; tc = tc->next) { if (tc->refCount) - afs_warn("conn at %x (server %x) is held\n", tc, + afs_warn("conn at %p (server %x) is held\n", tc, sa->sa_ip); } } @@ -262,9 +262,9 @@ afs_CheckLocks(void) for (i = 0; i < NVOLS; i++) { for (tv = afs_volumes[i]; tv; tv = tv->next) { if (CheckLock(&tv->lock)) - afs_warn("volume at %x is locked\n", tv); + afs_warn("volume at %p is locked\n", tv); if (tv->refCount) - afs_warn("volume at %x is held\n", tv); + afs_warn("volume at %p is held\n", tv); } } }