From 53beac2e23bcffe632bb837c97003998e6986ce9 Mon Sep 17 00:00:00 2001 From: Vladimir Mezentsev Date: Mon, 23 Oct 2023 19:55:01 -0700 Subject: gprofng: Fix -Wformat= warnings Added format attribute to several gprofng functions. Fixed -Wformat= warnings. gprofng/ChangeLog 2023-10-23 Vladimir Mezentsev * libcollector/heaptrace.c: Fixed -Wformat= warnings. * libcollector/hwprofile.c: Likewise. * libcollector/iolib.c: Likewise. * libcollector/iotrace.c: Likewise. * libcollector/jprofile.c: Likewise. * libcollector/profile.c: Likewise. * libcollector/synctrace.c: Likewise. * src/ClassFile.cc: Likewise. * src/SourceFile.cc: Likewise. * libcollector/libcol_util.h: Added format attribute. * src/Emsg.h: Likewise. * src/collector_module.h: Likewise. * src/data_pckts.h: Define fld_sizeof. --- gprofng/src/ClassFile.cc | 2 +- gprofng/src/Emsg.h | 3 ++- gprofng/src/SourceFile.cc | 6 ++++-- gprofng/src/collector_module.h | 11 +++++++---- gprofng/src/data_pckts.h | 1 + 5 files changed, 15 insertions(+), 8 deletions(-) (limited to 'gprofng/src') diff --git a/gprofng/src/ClassFile.cc b/gprofng/src/ClassFile.cc index 0f1d468..d59c963 100644 --- a/gprofng/src/ClassFile.cc +++ b/gprofng/src/ClassFile.cc @@ -1594,7 +1594,7 @@ ClassFile::get_disasm (uint64_t inst_address, uint64_t end_address, { append_msg (CMSG_ERROR, GTXT ("Cannot disassemble class file %s (%s), implausible size = %lld"), get_name (), dbeFile->get_location (), - (end_address - start_address)); + (long long) (end_address - start_address)); inst_size = 0; return NULL; } diff --git a/gprofng/src/Emsg.h b/gprofng/src/Emsg.h index bed664b..9dbacea 100644 --- a/gprofng/src/Emsg.h +++ b/gprofng/src/Emsg.h @@ -105,7 +105,8 @@ public: Vector *msgs; void remove_msg (Emsg *msg); Emsg *get_error (); - Emsg *append_msg (Cmsg_warn w, const char *fmt, ...); + Emsg *append_msg (Cmsg_warn w, const char *fmt, ...) + __attribute__ ((format (printf, 3, 4))); void append_msgs (Vector *lst); }; diff --git a/gprofng/src/SourceFile.cc b/gprofng/src/SourceFile.cc index 35629cc..f3809c8 100644 --- a/gprofng/src/SourceFile.cc +++ b/gprofng/src/SourceFile.cc @@ -135,7 +135,8 @@ SourceFile::readSource () DbeLine *p = v->get (i); if (p->lineno >= srcLines->size ()) append_msg (CMSG_ERROR, GTXT ("Wrong line number %d. '%s' has only %d lines"), - p->lineno, dbeFile->get_location (), srcLines->size ()); + (int) p->lineno, dbeFile->get_location (), + (int) srcLines->size ()); } delete v; } @@ -167,7 +168,8 @@ SourceFile::find_dbeline (Function *func, int lineno) if (dbeLine == NULL) append_msg (CMSG_ERROR, GTXT ("Wrong line number %d. '%s' has only %d lines"), - lineno, dbeFile->get_location (), lines->size ()); + (int) lineno, dbeFile->get_location (), + (int) lines->size ()); } else { diff --git a/gprofng/src/collector_module.h b/gprofng/src/collector_module.h index 07bf362..67dcad6 100644 --- a/gprofng/src/collector_module.h +++ b/gprofng/src/collector_module.h @@ -53,7 +53,8 @@ typedef struct CollectorUtilFuncs char *(*fgets)(char *s, int n, FILE *stream); FILE *(*fopen)(const char *filename, const char *mode); pid_t (*vfork)(); - int (*fprintf)(FILE *stream, const char *format, ...); + int (*fprintf)(FILE *stream, const char *format, ...) + __attribute__ ((format (printf, 2, 3))); void (*free)(void *ptr); int (*fstat)(int fd, struct stat *buf); int (*getcontext)(ucontext_t *ucp); @@ -82,7 +83,8 @@ typedef struct CollectorUtilFuncs int (*setenv)(const char *name, const char *value, int overwrite); int (*sigfillset)(sigset_t *set); int (*sigprocmask)(int how, const sigset_t *set, sigset_t *oldset); - int (*snprintf)(char *str, size_t size, const char *format, ...); + int (*snprintf)(char *str, size_t size, const char *format, ...) + __attribute__ ((format (printf, 3, 4))); int (*stack_getbounds)(); char *(*strchr)(const char *name, int c); int (*strcmp)(const char *s1, const char *s2); @@ -168,12 +170,13 @@ typedef struct CollectorInterface CollectorModule (*registerModule)(struct ModuleInterface*); const char *(*getParams)(); const char *(*getExpDir)(); - int (*writeLog)(char *format, ...); + int (*writeLog)(char *format, ...) __attribute__ ((format (printf, 1, 2))); FrameInfo (*getFrameInfo)(CollectorModule modl, HiResTime ts, int mode, void *arg); FrameInfo (*getUID)(CM_Array *arg); FrameInfo (*getUID2)(CM_Array *arg, FrameInfo uid); int (*getStackTrace)(void *buf, int size, void *bptr, void *eptr, void *arg); - int (*writeMetaData)(CollectorModule modl, char *format, ...); + int (*writeMetaData)(CollectorModule modl, char *format, ...) + __attribute__ ((format (printf, 2, 3))); /* writeDataRecord ensures that the header is filled in, and then calls writeDataPacket */ int (*writeDataRecord)(CollectorModule modl, struct Common_packet *pckt); diff --git a/gprofng/src/data_pckts.h b/gprofng/src/data_pckts.h index 484edae..eecd4e9 100644 --- a/gprofng/src/data_pckts.h +++ b/gprofng/src/data_pckts.h @@ -51,6 +51,7 @@ typedef uint32_t Size_type; /* size_t for 32 bit apps */ #define SP_FAILED_UNWIND_MARKER ((uint64_t)(-3)) #define PROFILE_BUFFER_CHUNK 16384 +#define fld_sizeof(t, f) (sizeof (((t *)0)->f)) typedef enum { -- cgit v1.1