Skip to content

Commit

Permalink
Added USBI_PRINTFLIKE to allow finding printf format string mistakes
Browse files Browse the repository at this point in the history
Fixed one such misktake

Closes #506

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
  • Loading branch information
seanm authored and hjelmn committed Jan 9, 2019
1 parent 92a5686 commit dc2c45c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libusb/io.c
Expand Up @@ -2598,7 +2598,7 @@ int API_EXPORTED libusb_get_next_timeout(libusb_context *ctx,
timerclear(tv);
} else {
timersub(&next_timeout, &cur_tv, tv);
usbi_dbg("next timeout in %d.%06ds", tv->tv_sec, tv->tv_usec);
usbi_dbg("next timeout in %ld.%06lds", (long)tv->tv_sec, (long)tv->tv_usec);
}

return 1;
Expand Down
14 changes: 12 additions & 2 deletions libusb/libusbi.h
Expand Up @@ -62,6 +62,16 @@
*/
#define API_EXPORTED LIBUSB_CALL DEFAULT_VISIBILITY

/* Macro to decorate printf-like functions, in order to get
* compiler warnings about format string mistakes.
*/
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
#define USBI_PRINTFLIKE(formatarg, firstvararg) \
__attribute__((__format__ (__printf__, formatarg, firstvararg)))
#else
#define USBI_PRINTFLIKE(formatarg, firstvararg)
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -216,10 +226,10 @@ int usbi_vsnprintf(char *dst, size_t size, const char *format, va_list ap);
#endif /* defined(_MSC_VER) && (_MSC_VER < 1900) */

void usbi_log(struct libusb_context *ctx, enum libusb_log_level level,
const char *function, const char *format, ...);
const char *function, const char *format, ...) USBI_PRINTFLIKE(4, 5);

void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
const char *function, const char *format, va_list args);
const char *function, const char *format, va_list args) USBI_PRINTFLIKE(4, 0);

#if !defined(_MSC_VER) || (_MSC_VER >= 1400)

Expand Down
2 changes: 1 addition & 1 deletion libusb/version_nano.h
@@ -1 +1 @@
#define LIBUSB_NANO 11329
#define LIBUSB_NANO 11330

0 comments on commit dc2c45c

Please sign in to comment.