From 7a0f0091f4ffea83e8ba9125f534b1c61f4c9468 Mon Sep 17 00:00:00 2001 From: paulc Date: Thu, 9 Sep 2004 16:16:29 +0000 Subject: [PATCH] Added gcc style printf argument check if supported. Fixed benign warning in gtkclient exposed by this check. git-svn-id: http://voip.null.ro/svn/yate@44 acf43c95-373e-0410-b603-e72c3f656dc1 --- clients/main-gtk.cpp | 4 ++-- configure.in | 13 ++++++++++++- yatengine.h | 18 +++++++++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/clients/main-gtk.cpp b/clients/main-gtk.cpp index 6d9a58ac..f1895337 100644 --- a/clients/main-gtk.cpp +++ b/clients/main-gtk.cpp @@ -43,7 +43,7 @@ void g_atexit(GVoidFunc func) it->func = func; it->next = _g_atexit_func_head; _g_atexit_func_head = it; - Debug(DebugInfo, "g_atexit: registered function 0x%08x\n", func); + Debug(DebugInfo, "g_atexit: registered function %p\n", func); } void g_atexit_unwind() @@ -51,7 +51,7 @@ void g_atexit_unwind() g_atexit_func_t* it; while(_g_atexit_func_head) { _g_atexit_func_head->func(); - Debug(DebugInfo, "g_atexit_unwind: called function 0x%08x\n", _g_atexit_func_head->func); + Debug(DebugInfo, "g_atexit_unwind: called function %p\n", _g_atexit_func_head->func); it = _g_atexit_func_head; _g_atexit_func_head = _g_atexit_func_head->next; free(it); diff --git a/configure.in b/configure.in index b16f6fa4..b5723c3d 100644 --- a/configure.in +++ b/configure.in @@ -7,6 +7,17 @@ AC_PROG_CXX AC_PROG_CC AC_PROG_AWK +# Check if gcc style printf argument check is supported +HAVE_GCC_FORMAT_CHECK="" +AC_MSG_CHECKING([for gcc printf format typechecks]) +SAVE_CFLAGS="$CFLAGS" +CFLAGS="$CFLAGS -Wall -Werror" +AC_TRY_COMPILE([],[void f(void*x,const char*f,...) __attribute__((format(printf,2,3))); ],[ac_cv_format_checks=yes],[ac_cv_format_checks=no]) +if [[ "x$ac_cv_format_checks" = "xyes" ]]; then + HAVE_GCC_FORMAT_CHECK="-DHAVE_GCC_FORMAT_CHECK" +fi +AC_MSG_RESULT([$ac_cv_format_checks]) + # Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC @@ -281,7 +292,7 @@ AC_SUBST(HAVE_GTK) AC_SUBST(GTK_INC) AC_SUBST(GTK_LIB) -MODULE_CFLAGS="-fno-exceptions -fno-check-new -frtti -fPIC" +MODULE_CFLAGS="-fno-exceptions -fno-check-new -frtti -fPIC $HAVE_GCC_FORMAT_CHECK" MODULE_LDFLAGS="-export-dynamic -shared -Wl,--retain-symbols-file,/dev/null" AC_SUBST(MODULE_CFLAGS) AC_SUBST(MODULE_LDFLAGS) diff --git a/yatengine.h b/yatengine.h index 99032160..6aa26946 100644 --- a/yatengine.h +++ b/yatengine.h @@ -54,7 +54,11 @@ bool debugAt(int level); * @param format A printf() style format string * @return True if message was output, false otherwise */ -bool Debug(int level, const char *format, ...); +bool Debug(int level, const char *format, ...) +#ifdef HAVE_GCC_FORMAT_CHECK +__attribute__((format(printf,2,3))) +#endif +; /** * Outputs a debug string for a specific facility. @@ -63,14 +67,22 @@ bool Debug(int level, const char *format, ...); * @param format A printf() style format string * @return True if message was output, false otherwise */ -bool Debug(const char *facility, int level, const char *format, ...); +bool Debug(const char *facility, int level, const char *format, ...) +#ifdef HAVE_GCC_FORMAT_CHECK +__attribute__((format(printf,3,4))) +#endif +; /** * Outputs a string to the debug console with formatting * @param facility Facility that outputs the message * @param format A printf() style format string */ -void Output(const char *format, ...); +void Output(const char *format, ...) +#ifdef HAVE_GCC_FORMAT_CHECK +__attribute__((format(printf,1,2))) +#endif +; /** * An object that logs messages on creation and destruction