diff --git a/epan/Makefile.common b/epan/Makefile.common index 65762fa9a0..670bc3b668 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -121,6 +121,7 @@ LIBETHEREAL_INCLUDES = \ filesystem.h \ follow.h \ frame_data.h \ + gnuc_format_check.h \ h225-persistentdata.h \ in_cksum.h \ ipproto.h \ diff --git a/epan/column-utils.h b/epan/column-utils.h index a02746fbe5..c503ddcbc9 100644 --- a/epan/column-utils.h +++ b/epan/column-utils.h @@ -30,6 +30,7 @@ #define COL_MAX_LEN 256 #define COL_MAX_INFO_LEN 4096 +#include "gnuc_format_check.h" #include "column_info.h" #include "packet_info.h" @@ -48,23 +49,15 @@ extern gint check_col(column_info *, gint); extern void col_set_fence(column_info *, gint); extern void col_clear(column_info *, gint); extern void col_set_str(column_info *, gint, const gchar *); -#if __GNUC__ >= 2 extern void col_add_fstr(column_info *, gint, const gchar *, ...) - __attribute__((format (printf, 3, 4))); + GNUC_FORMAT_CHECK(printf, 3, 4); extern void col_append_fstr(column_info *, gint, const gchar *, ...) - __attribute__((format (printf, 3, 4))); + GNUC_FORMAT_CHECK(printf, 3, 4); extern void col_append_sep_fstr(column_info *, gint, const gchar *sep, const gchar *fmt, ...) - __attribute__((format (printf, 4, 5))); + GNUC_FORMAT_CHECK(printf, 4, 5); extern void col_prepend_fstr(column_info *, gint, const gchar *, ...) - __attribute__((format (printf, 3, 4))); -#else -extern void col_add_fstr(column_info *, gint, const gchar *, ...); -extern void col_append_fstr(column_info *, gint, const gchar *, ...); -extern void col_append_sep_fstr(column_info *, gint, const gchar *sep, - const gchar *fmt, ...); -extern void col_prepend_fstr(column_info *, gint, const gchar *, ...); -#endif + GNUC_FORMAT_CHECK(printf, 3, 4); extern void col_add_str(column_info *, gint, const gchar *); extern void col_append_str(column_info *, gint, const gchar *); extern void col_append_sep_str(column_info *, gint, const gchar *sep, diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index b7d35cad25..1c1ef49d0b 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -275,8 +275,6 @@ show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, col_append_str(pinfo->cinfo, COL_INFO, "[Short Frame]"); item = proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0, "[Short Frame: %s]", pinfo->current_proto); - expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, - "Short Frame"); break; case ReportedBoundsError: @@ -299,8 +297,9 @@ show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, pinfo->current_proto, pinfo->fd->num, exception_message == NULL ? dissector_error_nomsg : exception_message); - expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, - exception_message == NULL ? + expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, + "%s", + exception_message == NULL ? dissector_error_nomsg : exception_message); if (exception_message != NULL) g_free(exception_message); diff --git a/epan/expert.h b/epan/expert.h index c44a80fab4..235104b10c 100644 --- a/epan/expert.h +++ b/epan/expert.h @@ -27,6 +27,8 @@ #ifndef __EXPERT_H__ #define __EXPERT_H__ +#include "gnuc_format_check.h" + /** only for internal and display use */ typedef struct expert_info_s { @@ -45,7 +47,6 @@ extern void expert_cleanup(void); /** Add an expert info. - * XXX - add gcc format string check. @param pinfo packet info of the currently processed packet @param pi current protocol item (or NULL) @@ -54,7 +55,8 @@ expert_cleanup(void); @param format printf like format string with further infos */ extern void -expert_add_info_format( -packet_info *pinfo, proto_item *pi, int group, int severity, const char *format, ...); +expert_add_info_format(packet_info *pinfo, proto_item *pi, int group, + int severity, const char *format, ...) + GNUC_FORMAT_CHECK(printf, 5, 6); #endif /* __EXPERT_H__ */ diff --git a/epan/gnuc_format_check.h b/epan/gnuc_format_check.h new file mode 100644 index 0000000000..31dcbeea89 --- /dev/null +++ b/epan/gnuc_format_check.h @@ -0,0 +1,39 @@ +/* gnuc_format_check.h + * Definitions of macro to conditionally do GCC format checks + * + * $Id$ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GNUC_FORMAT_CHECK_H__ +#define __GNUC_FORMAT_CHECK_H__ + +/** GNUC has the ability to check format strings that follow the syntax used in printf and others. + Hide the differences between different compilers in this GNUC_FORMAT_CHECK macro. + @param archetype one of: printf, scanf, strftime or strfmon + @param string_index specifies which argument is the format string argument (starting from 1) + @param first_to_check is the number of the first argument to check against the format string */ +#if __GNUC__ >= 2 + #define GNUC_FORMAT_CHECK(archetype, string_index, first_to_check) __attribute__((format (archetype, string_index, first_to_check))) +#else + #define GNUC_FORMAT_CHECK(archetype, string_index, first_to_check) +#endif + +#endif /* gnuc-format-check.h */ diff --git a/epan/proto.h b/epan/proto.h index 50618acf98..edb6b610df 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -45,6 +45,7 @@ #include +#include "gnuc_format_check.h" #include "ipv4.h" #include "nstime.h" #include "tvbuff.h" @@ -123,19 +124,6 @@ typedef struct _protocol protocol_t; g_strdup_printf("%s:%u: failed assertion \"%s\"", \ file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression)))) -/** GNUC has the ability to check format strings that follow the syntax used in printf and others. - Hide the differences between different compilers in this GNUC_FORMAT_CHECK macro. - @param archetype one of: printf, scanf, strftime or strfmon - @param string_index specifies which argument is the format string argument (starting from 1) - @param first_to_check is the number of the first argument to check against the format string - @todo as this check is also done at some other places too, move this macro to a more central place? */ -#if __GNUC__ >= 2 - #define GNUC_FORMAT_CHECK(archetype, string_index, first_to_check) __attribute__((format (archetype, string_index, first_to_check))) -#else - #define GNUC_FORMAT_CHECK(archetype, string_index, first_to_check) -#endif - - /** radix for decimal values, used in header_field_info.display */ typedef enum { BASE_NONE, /**< none */