From db949b7fade69d7eb1e38ad85d5b822c443306cb Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Wed, 7 Oct 2009 14:52:02 -0500 Subject: [PATCH] Correct and use AFS_SIZET_FMT On *nix, a size_t needs either %lu or %u to be interpolated in a string, depending on if we're on an ILP32 arch or not. Define AFS_SIZET_FMT accordingly, and actually use AFS_SIZET_FMT when we try to print a size_t. This removes numerous -Wformat warnings, at least when building on i386_linux26. Reviewed-on: http://gerrit.openafs.org/592 Reviewed-by: Matt Benjamin Tested-by: Jeffrey Altman Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/bozo/bosserver.c | 2 +- src/config/stds.h | 6 +++++- src/gtx/curseswindows.c | 12 ++++++------ src/gtx/lightobject.c | 4 ++-- src/gtx/objects.c | 4 ++-- src/gtx/textcb.c | 2 +- src/gtx/textobject.c | 5 ++--- src/kauth/rebuild.c | 6 +++--- src/ptserver/db_verify.c | 4 ++-- src/ptserver/ptserver.c | 2 +- src/rx/rx.c | 2 +- src/scout/scout.c | 2 +- src/uss/uss_acl.c | 2 +- src/venus/cmdebug.c | 2 +- src/viced/viced.c | 5 +++-- src/vlserver/cnvldb.c | 2 +- src/vlserver/vlserver.c | 2 +- src/volser/volmain.c | 2 +- src/xstat/xstat_cm.c | 2 +- src/xstat/xstat_fs.c | 2 +- 20 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/bozo/bosserver.c b/src/bozo/bosserver.c index f6c41bea6..df369028a 100644 --- a/src/bozo/bosserver.c +++ b/src/bozo/bosserver.c @@ -835,7 +835,7 @@ main(int argc, char **argv, char **envp) rxMaxMTU = atoi(argv[++code]); if ((rxMaxMTU < RX_MIN_PACKET_SIZE) || (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) { - printf("rxMaxMTU %d invalid; must be between %d-%lu\n", + printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n", rxMaxMTU, RX_MIN_PACKET_SIZE, RX_MAX_PACKET_DATA_SIZE); exit(1); diff --git a/src/config/stds.h b/src/config/stds.h index 9087c7182..1f7af6274 100644 --- a/src/config/stds.h +++ b/src/config/stds.h @@ -290,8 +290,12 @@ typedef struct afsUUID afsUUID; #define AFS_INT64_FMT "lld" #define AFS_UINT64_FMT "llu" #define AFS_PTR_FMT "p" +#ifdef AFS_64BITPOINTER_ENV +#define AFS_SIZET_FMT "lu" +#else #define AFS_SIZET_FMT "u" -#endif +#endif /* AFS_64BITPOINTER_ENV */ +#endif /* AFS_NT40_ENV */ /* Functions to safely cast afs_int32 and afs_uint32 so they can be used in * printf statemements with %ld and %lu diff --git a/src/gtx/curseswindows.c b/src/gtx/curseswindows.c index 6d60096fb..a5e59be9a 100644 --- a/src/gtx/curseswindows.c +++ b/src/gtx/curseswindows.c @@ -121,13 +121,13 @@ gator_cursesgwin_init(int adebug) */ if (curses_debug) fprintf(stderr, - "[%s:%s] Allocating %lu bytes for curses window private space in base window\n", + "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for curses window private space in base window\n", mn, rn, sizeof(struct gator_cursesgwin)); c_data = (struct gator_cursesgwin *)malloc(sizeof(struct gator_cursesgwin)); if (c_data == (struct gator_cursesgwin *)0) { fprintf(stderr, - "[%s:%s] Can't allocate %lu bytes for curses window private space in base window\n", + "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for curses window private space in base window\n", mn, rn, sizeof(struct gator_cursesgwin)); return (-1); } @@ -205,12 +205,12 @@ gator_cursesgwin_create(void * rock) if (curses_debug) fprintf(stderr, - "[%s:%s] Allocating %lu bytes for new gwin structure\n", mn, + "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for new gwin structure\n", mn, rn, sizeof(struct gwin)); newgwin = (struct gwin *)malloc(sizeof(struct gwin)); if (newgwin == NULL) { fprintf(stderr, - "[%s:%s] Can't malloc() %lu bytes for new gwin structure: Errno is %d\n", + "[%s:%s] Can't malloc() %" AFS_SIZET_FMT " bytes for new gwin structure: Errno is %d\n", mn, rn, sizeof(struct gwin), errno); return (NULL); } @@ -226,13 +226,13 @@ gator_cursesgwin_create(void * rock) if (curses_debug) fprintf(stderr, - "[%s:%s] Allocating %lu bytes for curses window private space\n", + "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for curses window private space\n", mn, rn, sizeof(struct gator_cursesgwin)); c_data = (struct gator_cursesgwin *)malloc(sizeof(struct gator_cursesgwin)); if (c_data == (struct gator_cursesgwin *)0) { fprintf(stderr, - "[%s:%s] Can't allocate %lu bytes for curses window private space\n", + "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for curses window private space\n", mn, rn, sizeof(struct gator_cursesgwin)); free(newgwin); return (NULL); diff --git a/src/gtx/lightobject.c b/src/gtx/lightobject.c index 67f5748c4..83f97dd15 100644 --- a/src/gtx/lightobject.c +++ b/src/gtx/lightobject.c @@ -85,7 +85,7 @@ gator_light_create(struct onode *light_onp, struct onode_createparams *params) (struct gator_lightobj *)malloc(sizeof(struct gator_lightobj)); if (light_data == (struct gator_lightobj *)0) { fprintf(stderr, - "[%s:%s] Can't allocate %lu bytes for light object private data region, errno is %d\n", + "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for light object private data region, errno is %d\n", mn, rn, sizeof(struct gator_lightobj), errno); return (errno); } @@ -94,7 +94,7 @@ gator_light_create(struct onode *light_onp, struct onode_createparams *params) (struct gwin_strparams *)malloc(sizeof(struct gwin_strparams)); if (light_strparams == (struct gwin_strparams *)0) { fprintf(stderr, - "[%s:%s] Can't allocate %lu bytes for light object label in private data region, errno is %d\n", + "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for light object label in private data region, errno is %d\n", mn, rn, sizeof(struct gwin_strparams), errno); free(light_data); return (errno); diff --git a/src/gtx/objects.c b/src/gtx/objects.c index b2b8e66ba..51e004cec 100644 --- a/src/gtx/objects.c +++ b/src/gtx/objects.c @@ -187,12 +187,12 @@ gator_objects_create(struct onode_createparams *params) if (objects_debug) fprintf(stderr, - "[%s:%s] Allocating %lu bytes for new onode structure\n", mn, + "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for new onode structure\n", mn, rn, sizeof(struct onode)); new_onode = (struct onode *)malloc(sizeof(struct onode)); if (new_onode == NULL) { fprintf(stderr, - "[%s:%s] Can't allocate %lu bytes for new onode structure; errno is %d\n", + "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for new onode structure; errno is %d\n", mn, rn, sizeof(struct onode), errno); return (NULL); } diff --git a/src/gtx/textcb.c b/src/gtx/textcb.c index f27683c71..3193cf5a4 100644 --- a/src/gtx/textcb.c +++ b/src/gtx/textcb.c @@ -587,7 +587,7 @@ gator_textcb_Delete(struct gator_textcb_hdr *a_cbhdr) a_cbhdr->entry[0].textp = NULL; if (gator_textcb_debug) - fprintf(stderr, "[%s]: Freeing text entry array at %p (%lu bytes)\n", + fprintf(stderr, "[%s]: Freeing text entry array at %p (%" AFS_SIZET_FMT " bytes)\n", rn, a_cbhdr->entry, (a_cbhdr->maxEntriesStored * sizeof(struct gator_textcb_entry))); diff --git a/src/gtx/textobject.c b/src/gtx/textobject.c index 9604558b9..9aac1125c 100644 --- a/src/gtx/textobject.c +++ b/src/gtx/textobject.c @@ -11,7 +11,6 @@ * Description: * Implementation of the gator text object. *------------------------------------------------------------------------*/ -#define IGNORE_STDS_H #include #include @@ -86,12 +85,12 @@ gator_text_create(struct onode *text_onp, struct onode_createparams *params) */ if (objects_debug) fprintf(stderr, - "[%s:%s] Allocating %lu bytes for text object private data region\n", + "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for text object private data region\n", mn, rn, sizeof(struct gator_textobj)); text_data = (struct gator_textobj *)malloc(sizeof(struct gator_textobj)); if (text_data == (struct gator_textobj *)0) { fprintf(stderr, - "[%s:%s] Can't allocate %lu bytes for text object private data region, errno is %d\n", + "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for text object private data region, errno is %d\n", mn, rn, sizeof(struct gator_textobj), errno); return (errno); } diff --git a/src/kauth/rebuild.c b/src/kauth/rebuild.c index 760deeeed..5f2c66bf3 100644 --- a/src/kauth/rebuild.c +++ b/src/kauth/rebuild.c @@ -63,7 +63,7 @@ readUbikHeader(void) /* now read the info */ r = read(fd, &uheader, sizeof(uheader)); if (r != sizeof(uheader)) { - printf("error: read of %lu bytes failed: %d %d\n", sizeof(uheader), r, + printf("error: read of %" AFS_SIZET_FMT " bytes failed: %d %d\n", sizeof(uheader), r, errno); return (-1); } @@ -331,7 +331,7 @@ CheckHeader(struct kaheader *header) if (header->headerSize != sizeof(struct kaheader)) { code++; fprintf(stderr, - "HEADER SIZE WRONG: file indicates %d, should be %lu\n", + "HEADER SIZE WRONG: file indicates %d, should be %" AFS_SIZET_FMT "\n", header->headerSize, sizeof(struct kaheader)); } if (header->hashsize != HASHSIZE) { @@ -504,7 +504,7 @@ WorkerBee(struct cmd_syndesc *as, void *arock) i = NameHash(&entry); if (i != j) { fprintf(stderr, - "Entry %lu, %s, found in hash chain %d (should be %d)\n", + "Entry %" AFS_SIZET_FMT ", %s, found in hash chain %d (should be %d)\n", ((index - sizeof(struct kaheader)) / sizeof(struct kaentry)), EntryName(&entry), j, i); diff --git a/src/ptserver/db_verify.c b/src/ptserver/db_verify.c index ce363785d..80ee4679e 100644 --- a/src/ptserver/db_verify.c +++ b/src/ptserver/db_verify.c @@ -211,8 +211,8 @@ readUbikHeader(struct misc_data *misc) /* now read the info */ r = read(fd, &uheader, sizeof(uheader)); if (r != sizeof(uheader)) { - printf("error: read of %lu bytes failed: %d %d\n", sizeof(uheader), r, - errno); + printf("error: read of %" AFS_SIZET_FMT " bytes failed: %d %d\n", + sizeof(uheader), r, errno); return (-1); } diff --git a/src/ptserver/ptserver.c b/src/ptserver/ptserver.c index 0a764ba4c..79b5ef40c 100644 --- a/src/ptserver/ptserver.c +++ b/src/ptserver/ptserver.c @@ -347,7 +347,7 @@ main(int argc, char **argv) rxMaxMTU = atoi(argv[++a]); if ((rxMaxMTU < RX_MIN_PACKET_SIZE) || (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) { - printf("rxMaxMTU %d invalid; must be between %d-%lu\n", + printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n", rxMaxMTU, RX_MIN_PACKET_SIZE, RX_MAX_PACKET_DATA_SIZE); PT_EXIT(1); diff --git a/src/rx/rx.c b/src/rx/rx.c index a01f3eb9d..5c344d8a6 100755 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -6462,7 +6462,7 @@ rx_PrintTheseStats(FILE * file, struct rx_statistics *s, int size, if (size != sizeof(struct rx_statistics)) { fprintf(file, - "Unexpected size of stats structure: was %d, expected %lud\n", + "Unexpected size of stats structure: was %d, expected %" AFS_SIZET_FMT "\n", size, sizeof(struct rx_statistics)); } diff --git a/src/scout/scout.c b/src/scout/scout.c index 6623de00e..4ce9013d4 100644 --- a/src/scout/scout.c +++ b/src/scout/scout.c @@ -1781,7 +1781,7 @@ execute_scout(int a_numservers, struct cmd_item *a_srvname, int a_pkg) /*Debugging */ if (scout_debug) - fprintf(scout_debugfd, "[%s] Scout label is '%s', %lu chars\n", rn, + fprintf(scout_debugfd, "[%s] Scout label is '%s', %" AFS_SIZET_FMT " chars\n", rn, lightdata->label, strlen(lightdata->label)); } diff --git a/src/uss/uss_acl.c b/src/uss/uss_acl.c index 33eac2a9b..65e68b171 100644 --- a/src/uss/uss_acl.c +++ b/src/uss/uss_acl.c @@ -563,7 +563,7 @@ uss_acl_SetAccess(char *a_access, int a_clear, int a_negative) tp = uss_common_FieldCp(path_field, a_access, ' ', sizeof(path_field), &overflow); if (overflow) { - fprintf(stderr, "%s: * Pathname field too long (max is %lu chars)\n", + fprintf(stderr, "%s: * Pathname field too long (max is %" AFS_SIZET_FMT " chars)\n", uss_whoami, sizeof(path_field)); return (-1); } diff --git a/src/venus/cmdebug.c b/src/venus/cmdebug.c index e1f19f540..e192ca760 100644 --- a/src/venus/cmdebug.c +++ b/src/venus/cmdebug.c @@ -58,7 +58,7 @@ PrintCacheConfig(struct rx_connection *aconn) struct cm_initparams_v1 *c1; if (c.cacheConfig_len != sizeof(*c1) / sizeof(afs_uint32)) { - printf("cmdebug: configuration data size mismatch (%d != %lu)\n", + printf("cmdebug: configuration data size mismatch (%d != %" AFS_SIZET_FMT ")\n", c.cacheConfig_len, sizeof(*c1) / sizeof(afs_uint32)); return 0; } diff --git a/src/viced/viced.c b/src/viced/viced.c index 22c1b7f52..2a99d0547 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -257,7 +257,8 @@ CheckDescriptors(void *unused) for (i = 0; i < tsize; i++) { if (afs_fstat(i, &status) != -1) { printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i, - status.st_dev, status.st_ino, + (unsigned int) status.st_dev, + (unsigned int) status.st_ino, (unsigned int) status.st_size, status.st_mode); } @@ -1293,7 +1294,7 @@ ParseArgs(int argc, char *argv[]) rxMaxMTU = atoi(argv[++i]); if ((rxMaxMTU < RX_MIN_PACKET_SIZE) || (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) { - printf("rxMaxMTU %d%% invalid; must be between %d-%lu\n", + printf("rxMaxMTU %d%% invalid; must be between %d-%" AFS_SIZET_FMT "\n", rxMaxMTU, RX_MIN_PACKET_SIZE, RX_MAX_PACKET_DATA_SIZE); return -1; diff --git a/src/vlserver/cnvldb.c b/src/vlserver/cnvldb.c index a3ea40a1e..6d591a4dd 100644 --- a/src/vlserver/cnvldb.c +++ b/src/vlserver/cnvldb.c @@ -334,7 +334,7 @@ printentry(int version, void *addr) if (vl3p->flags == VLFREE) return; - printf("%s\tPos=%lu NextIdHash=[%d:%d:%d] NextNameHash=%d\n", + printf("%s\tPos=%" AFS_SIZET_FMT " NextIdHash=[%d:%d:%d] NextNameHash=%d\n", vl3p->name, (oldpos - sizeof(struct vlentry_3)), vl3p->nextIdHash[0], vl3p->nextIdHash[1], vl3p->nextIdHash[2], vl3p->nextNameHash); diff --git a/src/vlserver/vlserver.c b/src/vlserver/vlserver.c index 743354b1e..325a60fcb 100644 --- a/src/vlserver/vlserver.c +++ b/src/vlserver/vlserver.c @@ -195,7 +195,7 @@ main(int argc, char **argv) rxMaxMTU = atoi(argv[++index]); if ((rxMaxMTU < RX_MIN_PACKET_SIZE) || (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) { - printf("rxMaxMTU %d invalid; must be between %d-%lu\n", + printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n", rxMaxMTU, RX_MIN_PACKET_SIZE, RX_MAX_PACKET_DATA_SIZE); return -1; diff --git a/src/volser/volmain.c b/src/volser/volmain.c index e40671112..28dafd6a8 100644 --- a/src/volser/volmain.c +++ b/src/volser/volmain.c @@ -332,7 +332,7 @@ main(int argc, char **argv) rxMaxMTU = atoi(argv[++code]); if ((rxMaxMTU < RX_MIN_PACKET_SIZE) || (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) { - printf("rxMaxMTU %d invalid; must be between %d-%lu\n", + printf("rxMaxMTU %d invalid; must be between %d-%" AFS_SIZET_FMT "\n", rxMaxMTU, RX_MIN_PACKET_SIZE, RX_MAX_PACKET_DATA_SIZE); exit(1); diff --git a/src/xstat/xstat_cm.c b/src/xstat/xstat_cm.c index 6d4b7b01d..8afbc92fd 100644 --- a/src/xstat/xstat_cm.c +++ b/src/xstat/xstat_cm.c @@ -474,7 +474,7 @@ xstat_cm_Init(int a_numServers, struct sockaddr_in *a_socketArray, malloc(a_numServers * sizeof(struct xstat_cm_ConnectionInfo)); if (xstat_cm_ConnInfo == (struct xstat_cm_ConnectionInfo *)0) { fprintf(stderr, - "[%s] Can't allocate %d connection info structs (%lu bytes)\n", + "[%s] Can't allocate %d connection info structs (%" AFS_SIZET_FMT " bytes)\n", rn, a_numServers, (a_numServers * sizeof(struct xstat_cm_ConnectionInfo))); return (-1); /*No cleanup needs to be done yet */ diff --git a/src/xstat/xstat_fs.c b/src/xstat/xstat_fs.c index 964754866..5beb3fb57 100644 --- a/src/xstat/xstat_fs.c +++ b/src/xstat/xstat_fs.c @@ -503,7 +503,7 @@ xstat_fs_Init(int a_numServers, struct sockaddr_in *a_socketArray, malloc(a_numServers * sizeof(struct xstat_fs_ConnectionInfo)); if (xstat_fs_ConnInfo == (struct xstat_fs_ConnectionInfo *)0) { fprintf(stderr, - "[%s] Can't allocate %d connection info structs (%lu bytes)\n", + "[%s] Can't allocate %d connection info structs (%" AFS_SIZET_FMT " bytes)\n", rn, a_numServers, (a_numServers * sizeof(struct xstat_fs_ConnectionInfo))); return (-1); /*No cleanup needs to be done yet */ -- 2.39.5