From 7f17b26a45c3e715e4b9e4b4bbc603c424b54e09 Mon Sep 17 00:00:00 2001 From: wmeier Date: Wed, 18 Mar 2009 15:03:46 +0000 Subject: [PATCH] From Jakub Zawadzki: g_gnprintf & etc: Use size of buffer [not size -1]; - As suggested actually use sizeof(...) rather than a numeric constant. - g_snprintf() and g_vsnprintf() since glib 1.3.12 do not return -1. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@27772 f5534014-38df-0310-8fa8-9805f1628bb7 --- epan/dissectors/packet-isakmp.c | 6 +++--- epan/expert.c | 5 +---- gtk/mac_lte_stat_dlg.c | 6 +++--- plugins/mate/mate_util.c | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/epan/dissectors/packet-isakmp.c b/epan/dissectors/packet-isakmp.c index 5e369cb102..bf6076af83 100644 --- a/epan/dissectors/packet-isakmp.c +++ b/epan/dissectors/packet-isakmp.c @@ -2661,7 +2661,7 @@ situation2str(guint32 type) if (type & SIT_IDENTITY) { ret = g_snprintf(msg, SIT_MSG_NUM-n, "%sIDENTITY", sep); - if (ret == -1 || ret >= SIT_MSG_NUM-n) { + if (ret >= SIT_MSG_NUM-n) { /* Truncated. */ return msg; } @@ -2674,7 +2674,7 @@ situation2str(guint32 type) return msg; } ret = g_snprintf(msg, SIT_MSG_NUM-n, "%sSECRECY", sep); - if (ret == -1 || ret >= SIT_MSG_NUM-n) { + if (ret >= SIT_MSG_NUM-n) { /* Truncated. */ return msg; } @@ -2687,7 +2687,7 @@ situation2str(guint32 type) return msg; } ret = g_snprintf(msg, SIT_MSG_NUM-n, "%sINTEGRITY", sep); - if (ret == -1 || ret >= SIT_MSG_NUM-n) { + if (ret >= SIT_MSG_NUM-n) { /* Truncated. */ return msg; } diff --git a/epan/expert.c b/epan/expert.c index 99080f74ff..ab7d9d845d 100644 --- a/epan/expert.c +++ b/epan/expert.c @@ -150,7 +150,6 @@ static void expert_set_info_vformat( packet_info *pinfo, proto_item *pi, int group, int severity, const char *format, va_list ap) { - int ret; /*tmp return value */ char formatted[300]; expert_info_t *ei; proto_tree *tree; @@ -167,9 +166,7 @@ packet_info *pinfo, proto_item *pi, int group, int severity, const char *format, } /* XXX - use currently nonexistant se_vsnprintf instead */ - ret = g_vsnprintf(formatted, sizeof(formatted), format, ap); - if ((ret == -1) || (ret >= (int)sizeof(formatted))) - formatted[sizeof(formatted) - 1] = '\0'; + g_vsnprintf(formatted, sizeof(formatted), format, ap); ei = ep_alloc(sizeof(expert_info_t)); ei->packet_num = pinfo->fd->num; diff --git a/gtk/mac_lte_stat_dlg.c b/gtk/mac_lte_stat_dlg.c index b73693dee9..4cb2aeb6ea 100644 --- a/gtk/mac_lte_stat_dlg.c +++ b/gtk/mac_lte_stat_dlg.c @@ -186,12 +186,12 @@ mac_lte_stat_reset(void *phs) /* Set the title */ if (mac_lte_stat_dlg_w != NULL) { - g_snprintf (title, 255, "Wireshark: LTE MAC Traffic Statistics: %s", + g_snprintf (title, sizeof(title), "Wireshark: LTE MAC Traffic Statistics: %s", cf_get_display_name(&cfile)); gtk_window_set_title(GTK_WINDOW(mac_lte_stat_dlg_w), title); } - g_snprintf(title, 255, "UL/DL-SCH data"); + g_snprintf(title, sizeof(title), "UL/DL-SCH data"); gtk_frame_set_label(GTK_FRAME(mac_lte_stat_ues_lb), title); memset(&common_stats, 0, sizeof(common_stats)); @@ -574,7 +574,7 @@ static void mac_lte_stat_dlg_create(void) hs->number_of_packets = 0; /* Set title */ - g_snprintf(title, 255, "Wireshark: LTE MAC Statistics: %s", + g_snprintf(title, sizeof(title), "Wireshark: LTE MAC Statistics: %s", cf_get_display_name(&cfile)); mac_lte_stat_dlg_w = window_new_with_geom(GTK_WINDOW_TOPLEVEL, title, "LTE MAC Statistics"); diff --git a/plugins/mate/mate_util.c b/plugins/mate/mate_util.c index caec284d16..ade8fb2285 100644 --- a/plugins/mate/mate_util.c +++ b/plugins/mate/mate_util.c @@ -242,7 +242,7 @@ gchar* scs_subscribe_printf(SCS_collection* c, gchar* fmt, ...) { static gchar buf[SCS_HUGE_SIZE]; va_start( list, fmt ); - g_vsnprintf(buf, SCS_HUGE_SIZE-1 ,fmt, list); + g_vsnprintf(buf, SCS_HUGE_SIZE, fmt, list); va_end( list ); return scs_subscribe(c,buf); -- 2.34.1