From d98d3060f880f4c7d4089fd2fb981ee08fd1486f Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Sat, 7 Nov 2009 11:52:59 +0000 Subject: [PATCH] Add printf-style format checking Add the AFS_ATTRIBUTE_FORMAT macro which can be used to turn on printf-like format checking for our va-arg log functions. Enable this checking for volser's Log(), and fix the fallout from doing so. Change-Id: Ic5ab93ba731856f1f90e894d711b0f84298ded12 Reviewed-on: http://gerrit.openafs.org/789 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/config/stds.h | 2 ++ src/volser/vol_split.c | 41 ++++++++++++++++++++---------------- src/volser/volser_internal.h | 2 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/config/stds.h b/src/config/stds.h index 300d83390..1d7007851 100644 --- a/src/config/stds.h +++ b/src/config/stds.h @@ -333,8 +333,10 @@ hdr_static_inline(unsigned long) afs_printable_uint32_lu(afs_uint32 d) { return #if !defined(__GNUC__) || __GNUC__ < 2 #define AFS_UNUSED +#define AFS_ATTRIBUTE_FORMAT(style,x,y) #else #define AFS_UNUSED __attribute__((unused)) +#define AFS_ATTRIBUTE_FORMAT(style,x,y) __attribute__((format(style, x, y))) #endif #endif /* OPENAFS_CONFIG_AFS_STDS_H */ diff --git a/src/volser/vol_split.c b/src/volser/vol_split.c index 0c2c24178..2ea92f257 100644 --- a/src/volser/vol_split.c +++ b/src/volser/vol_split.c @@ -353,8 +353,9 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, offset = (e->vN + 1 - class) << (vcp->logSize -1); if (FDH_SEEK(fdP, offset, 0) != offset || FDH_READ(fdP, vnode, vcp->diskSize) != vcp->diskSize) { - Log("Couldn't read in %s Index of volume %u at offset\n", - class ? "small":"large", V_id(vol), offset); + Log("Couldn't read in %s Index of volume %u at offset %" + AFS_UINT64_FMT "\n", class ? "small":"large", + V_id(vol), offset); code = EIO; goto Bad_Copy; } @@ -385,8 +386,9 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, vnode->cloned = 0; if (FDH_SEEK(fdP, offset, 0) != offset || FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) { - Log("Couldn't write in %s Index of volume %u at offset\n", - class ? "small":"large", V_id(vol), offset); + Log("Couldn't write in %s Index of volume %u at offset %" + AFS_UINT64_FMT "\n", class ? "small":"large", + V_id(vol), offset); code = EIO; goto Bad_Copy; } @@ -432,9 +434,9 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, vnode->cloned = 0; if (FDH_SEEK(newfdP, offset, 0) != offset || FDH_WRITE(newfdP, vnode, vcp->diskSize) != vcp->diskSize) { - Log("Couldn't write in %s Index of volume %u to offset\n", - class ? "small":"large", V_id(newvol), - offset); + Log("Couldn't write in %s Index of volume %u to offset %" + AFS_UINT64_FMT "\n", class ? "small":"large", + V_id(newvol), offset); code = EIO; goto Bad_Copy; } @@ -461,8 +463,8 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, offset = (where + 1 - class) << (vcp->logSize -1); if (FDH_SEEK(fdP, offset, 0) != offset || FDH_READ(fdP, vnode, vcp->diskSize) != vcp->diskSize) { - Log("Couldn't read in large Index of old volume %u at offset\n", - V_id(vol), offset); + Log("Couldn't read in large Index of old volume %u at offset %" + AFS_UINT64_FMT "\n", V_id(vol), offset); code = EIO; goto Bad_Copy; } @@ -474,8 +476,9 @@ afs_int32 copyVnodes(struct Msg *m, Volume *vol, Volume *newvol, IH_INIT(newh, newvol->device, V_parentId(newvol), newino); code = copyDir(m, h, newh); if (code) { - Log("splitvolume: copyDir failed for new root from %u.u.u to %u.1.1\n", - V_id(vol), where, vnode->uniquifier, V_id(newvol)); + Log("splitvolume: copyDir failed for new root from " + "%u.%u.%u to %u.1.1\n", + V_id(vol), where, vnode->uniquifier, V_id(newvol)); code = EIO; goto Bad_Copy; } @@ -671,14 +674,16 @@ deleteVnodes(Volume *vol, afs_int32 class, afs_uint64 size; offset = (e->vN + 1 - class) << (vcp->logSize -1); if (FDH_SEEK(fdP, offset, 0) != offset) { - Log("Couldn't seek in %s Index of volume %u to offset\n", - class ? "small":"large", V_id(vol), offset); + Log("Couldn't seek in %s Index of volume %u to offset %" + AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol), + offset); code = EIO; goto Bad_Delete; } if (FDH_READ(fdP, vnode, vcp->diskSize) != vcp->diskSize) { - Log("Couldn't read in %s Index of volume %u at offset\n", - class ? "small":"large", V_id(vol), offset); + Log("Couldn't read in %s Index of volume %u at offset %" + AFS_UINT64_FMT "\n", class ? "small":"large", V_id(vol), + offset); code = EIO; goto Bad_Delete; } @@ -698,9 +703,9 @@ deleteVnodes(Volume *vol, afs_int32 class, vnode->type = vNull; if (FDH_SEEK(fdP, offset, 0) != offset || FDH_WRITE(fdP, vnode, vcp->diskSize) != vcp->diskSize) { - Log("Couldn't write in %s Index of volume %u to offset\n", - class ? "small":"large", V_id(vol), - offset); + Log("Couldn't write in %s Index of volume %u to offset %" + AFS_UINT64_FMT "\n", class ? "small":"large", + V_id(vol), offset); } } } diff --git a/src/volser/volser_internal.h b/src/volser/volser_internal.h index d15803976..52a2dcf7b 100644 --- a/src/volser/volser_internal.h +++ b/src/volser/volser_internal.h @@ -11,7 +11,7 @@ #define AFS_SRC_VOLSER_INTERNAL_H /* common.c */ -extern void Log(const char *, ...); +extern void Log(const char *, ...) AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2); extern void InitErrTabs(void); /* vol_split.c */ -- 2.39.5