mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 01:26:58 +00:00
FreeTDM: Add gcc printf()-style format string checks to ftdm_log(), also add FTDM_(U)INT64_FMT and FTDM_TIME_FMT constants.
The format string checks already caught a couple crash-worthy bugs and this commit fixes a couple more. Also includes __ftdm_check_scanf(), for completeness (currently unused). Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
This commit is contained in:
@@ -216,7 +216,7 @@ FTDM_STR2ENUM_P(ftdm_str2ftdm_chan_type, ftdm_chan_type2str, ftdm_chan_type_t)
|
||||
/*! \brief Logging function prototype to be used for all FreeTDM logs
|
||||
* you should use ftdm_global_set_logger to set your own logger
|
||||
*/
|
||||
typedef void (*ftdm_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...);
|
||||
typedef void (*ftdm_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...) __ftdm_check_printf(5, 6);
|
||||
|
||||
/*! \brief Data queue operation functions
|
||||
* you can use ftdm_global_set_queue_handler if you want to override the default implementation (not recommended)
|
||||
|
@@ -121,6 +121,36 @@ extern "C" {
|
||||
#pragma comment(lib, "Winmm")
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compiler-specific format checking attributes
|
||||
* use these on custom functions that use printf/scanf-style
|
||||
* format strings (e.g. ftdm_log())
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
/**
|
||||
* Enable compiler-specific printf()-style format and argument checks on a function
|
||||
* @param fmtp Position of printf()-style format string parameter
|
||||
* @param argp Position of variable argument list ("...") parameter
|
||||
* @code
|
||||
* void log(const int level, const char *fmt, ...) __ftdm_check_printf(2, 3);
|
||||
* @endcode
|
||||
*/
|
||||
#define __ftdm_check_printf(fmtp, argp) __attribute__((format (printf, fmtp, argp)))
|
||||
/**
|
||||
* Enable compiler-specific scanf()-style format and argument checks on a function
|
||||
* @param fmtp Position of scanf()-style format string parameter
|
||||
* @param argp Position of variable argument list ("...") parameter
|
||||
* @code
|
||||
* void parse(struct foo *ctx, const char *fmt, ...) __ftdm_check_scanf(2, 3);
|
||||
* @endcode
|
||||
*/
|
||||
#define __ftdm_check_scanf(fmtp, argp) __attribute__((format (scanf, fmtp, argp)))
|
||||
#else
|
||||
#define __ftdm_check_printf(fmtp, argp)
|
||||
#define __ftdm_check_scanf(fmtp, argp)
|
||||
#endif
|
||||
|
||||
|
||||
#define FTDM_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) FT_DECLARE(_TYPE) _FUNC1 (const char *name); FT_DECLARE(const char *) _FUNC2 (_TYPE type);
|
||||
#define FTDM_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \
|
||||
FT_DECLARE(_TYPE) _FUNC1 (const char *name) \
|
||||
@@ -160,6 +190,8 @@ typedef __int16 int16_t;
|
||||
typedef __int8 int8_t;
|
||||
#define FTDM_O_BINARY O_BINARY
|
||||
#define FTDM_SIZE_FMT "Id"
|
||||
#define FTDM_INT64_FMT "lld"
|
||||
#define FTDM_UINT64_FMT "llu"
|
||||
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
|
||||
#else
|
||||
@@ -168,6 +200,13 @@ typedef __int8 int8_t;
|
||||
#else /* __WINDOWS__ */
|
||||
#define FTDM_O_BINARY 0
|
||||
#define FTDM_SIZE_FMT "zd"
|
||||
#if (defined(__SIZEOF_LONG__) && (__SIZEOF_LONG__ == 8)) || defined(__LP64__) || defined(__LLP64__)
|
||||
#define FTDM_INT64_FMT "ld"
|
||||
#define FTDM_UINT64_FMT "lu"
|
||||
#else
|
||||
#define FTDM_INT64_FMT "lld"
|
||||
#define FTDM_UINT64_FMT "llu"
|
||||
#endif
|
||||
#define FTDM_INVALID_SOCKET -1
|
||||
typedef int ftdm_socket_t;
|
||||
#include <stdio.h>
|
||||
|
@@ -53,6 +53,8 @@ extern "C" {
|
||||
|
||||
/*! \brief time data type */
|
||||
typedef uint64_t ftdm_time_t;
|
||||
/*! format string for ftdm_time_t */
|
||||
#define FTDM_TIME_FMT FTDM_UINT64_FMT
|
||||
|
||||
/*! \brief sleep x amount of milliseconds */
|
||||
#ifdef __WINDOWS__
|
||||
|
Reference in New Issue
Block a user