Move the definition of GNUC_FORMAT_CHECK() to its own header, use it in
column-utils.h, and add it to expert.h, so we check the arguments to "expert_add_info_format()", at least if the format argument is a constant string. Fix some more calls to "expert_add_info_format()" to pass it a format string. Don't record BoundsError exceptions as expert events - they merely reflect a capture done with a snapshot length too short to capture all of the packet (any case where it's caused by something else is a bug). svn path=/trunk/; revision=15776
This commit is contained in:
parent
fcc31e309f
commit
aba53424dd
|
@ -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 \
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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 <gerald@ethereal.com>
|
||||
* 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 */
|
14
epan/proto.h
14
epan/proto.h
|
@ -45,6 +45,7 @@
|
|||
|
||||
#include <glib.h>
|
||||
|
||||
#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 */
|
||||
|
|
Loading…
Reference in New Issue