From 2c25c64db395d2f2f73f8d2f66ae9886ce07ef8b Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Tue, 18 Feb 2014 11:27:53 +1100 Subject: [PATCH] Enable GNU GCC type checking of format arguments for our functions --- conman.h | 9 ++++++++- errormsg.h | 9 ++++++++- servlog.h | 11 +++++++++-- trace.h | 19 +++++++++++++------ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/conman.h b/conman.h index 8f085332..40308a3b 100644 --- a/conman.h +++ b/conman.h @@ -91,7 +91,14 @@ void SCSignalFunction(void *pCon, int iSignal, void *pSigData); /* ***************************** I/O ************************************** */ void SCSetOutputClass(SConnection * self, int iClass); int SCWrite(SConnection * self, char *pBuffer, int iOut); -int SCPrintf(SConnection * self, int iOut, char *fmt, ...); +#if __GNUC__ > 2 +#define G_GNUC_PRINTF( format_idx, arg_idx ) \ + __attribute__((__format__ (__printf__, format_idx, arg_idx))) +#else +#define G_GNUC_PRINTF( format_idx, arg_idx ) +#endif +int SCPrintf(SConnection * self, int iOut, char *fmt, ...) G_GNUC_PRINTF (3, 4); +#undef G_GNUC_PRINTF int SCRead(SConnection * self, char *pBuffer, int iBufLen); int SCPrompt(SConnection * pCon, char *pPrompt, char *pResult, int iLen); int SCSendOK(SConnection * self); diff --git a/errormsg.h b/errormsg.h index 5f792147..e7630edc 100644 --- a/errormsg.h +++ b/errormsg.h @@ -35,7 +35,14 @@ typedef struct { * \return the new error message list head */ -void ErrPutMsg(ErrList *list, char *fmt, ...); +#if __GNUC__ > 2 +#define G_GNUC_PRINTF( format_idx, arg_idx ) \ + __attribute__((__format__ (__printf__, format_idx, arg_idx))) +#else +#define G_GNUC_PRINTF( format_idx, arg_idx ) +#endif +void ErrPutMsg(ErrList *list, char *fmt, ...) G_GNUC_PRINTF (2, 3); +#undef G_GNUC_PRINTF /** \brief Get the most recent error message * \param list the error list diff --git a/servlog.h b/servlog.h index 0b928cd7..ebe788d1 100644 --- a/servlog.h +++ b/servlog.h @@ -20,9 +20,16 @@ void SICSLogWriteTime(char *ptext, OutCode eOut, struct timeval *tp); void SICSLogWriteHex(const char *text, int count, OutCode eOut); void SICSLogWriteHexTime(const char *text, int count, OutCode eOut, struct timeval *tp); -void SICSLogPrintf(OutCode eOut, const char *fmt, ...); +#if __GNUC__ > 2 +#define G_GNUC_PRINTF( format_idx, arg_idx ) \ + __attribute__((__format__ (__printf__, format_idx, arg_idx))) +#else +#define G_GNUC_PRINTF( format_idx, arg_idx ) +#endif +void SICSLogPrintf(OutCode eOut, const char *fmt, ...) G_GNUC_PRINTF (2, 3); void SICSLogTimePrintf(OutCode eOut, struct timeval *tp, const char *fmt, - ...); + ...) G_GNUC_PRINTF (3, 4); +#undef G_GNUC_PRINTF void SICSLogEnable(int flag); int KillCapture(SConnection * pCon); diff --git a/trace.h b/trace.h index afd6d71b..24a266d5 100644 --- a/trace.h +++ b/trace.h @@ -18,17 +18,24 @@ * the socket number, a host:port or something appropriate * which tells us where the stuff is going to or coming from. */ -void traceIO(char *id, char *format, ...); -void traceDevice(char *id, char *format, ...); -void traceCommand(char *id, char *format, ...); -void tracePar(char *id, char *format, ...); -void traceSys(char *id, char *format, ...); +#if __GNUC__ > 2 +#define G_GNUC_PRINTF( format_idx, arg_idx ) \ + __attribute__((__format__ (__printf__, format_idx, arg_idx))) +#else +#define G_GNUC_PRINTF( format_idx, arg_idx ) +#endif +void traceIO(char *id, char *format, ...) G_GNUC_PRINTF (2, 3); +void traceDevice(char *id, char *format, ...) G_GNUC_PRINTF (2, 3); +void traceCommand(char *id, char *format, ...) G_GNUC_PRINTF (2, 3); +void tracePar(char *id, char *format, ...) G_GNUC_PRINTF (2, 3); +void traceSys(char *id, char *format, ...) G_GNUC_PRINTF (2, 3); void traceprint(char *sub, char *id,char *data); /** * A debugging trace. This has to be switched on separately */ -void traceDebug(char *id, char *format, ...); +void traceDebug(char *id, char *format, ...) G_GNUC_PRINTF (2, 3); +#undef G_GNUC_PRINTF /* * 1 when tracing active, 0 else