From Jakub Zawadzki: g_gnprintf & etc: Use size of buffer [not size -1];
authorwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 18 Mar 2009 15:03:46 +0000 (15:03 +0000)
committerwmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 18 Mar 2009 15:03:46 +0000 (15:03 +0000)
  - 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
epan/expert.c
gtk/mac_lte_stat_dlg.c
plugins/mate/mate_util.c

index 5e369cb1020b4530f27f5fb7eee9dd33c1afa2ce..bf6076af83772f2ca68704b2faebc33cd720ed1a 100644 (file)
@@ -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;
     }
index 99080f74ff7c8eed3339d5e0d891884e27f19dec..ab7d9d845da22e161b6d572971bd65d0322660b5 100644 (file)
@@ -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;
index b73693dee981bb89aaa82f6f630f8340ffe70eae..4cb2aeb6ea4b9c740d9f16e4b21eb7a61305248c 100644 (file)
@@ -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");
 
index caec284d16037dbb582d51a13c5b8269aeaa7aca..ade8fb228564401a8723aa34143855612962eab5 100644 (file)
@@ -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_SIZEfmt, list);
        va_end( list );
 
        return scs_subscribe(c,buf);