In packet-cops.c use proto_item_append_text() instead of creating a
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 18 Jan 2006 20:02:19 +0000 (20:02 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 18 Jan 2006 20:02:19 +0000 (20:02 +0000)
separate buffer.  Fixes the current Buildbot failure.

Don't let the sprint_realloc_* functions reallocate ep_allocated memory.
Add comments warning against this in the future.

In emem.c, make sure we don't use an extra 100k every stinkin' time
someone wants to allocate memory when debugging is enabled.

Fixup whitespace.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@17051 f5534014-38df-0310-8fa8-9805f1628bb7

asn1/snmp/packet-snmp-template.c
epan/dissectors/packet-cops.c
epan/dissectors/packet-snmp.c
epan/emem.c

index cfddea4a1462392bfaa48ed1e02deed54ede7622..e20169361cd3e2909f5cd97a3b73def6cf6442b2 100644 (file)
@@ -263,6 +263,8 @@ format_oid(subid_t *oid, guint oid_length)
         * length of the result string.
         *
         * XXX - check for "sprint_realloc_objid()" failure.
+        * XXX - if we convert this to ep_alloc(), make sure the fourth
+        * argument to sprint_realloc_objid() is FALSE.
         */
        oid_string_len = 256;
        oid_string = malloc(oid_string_len);
@@ -270,7 +272,7 @@ format_oid(subid_t *oid, guint oid_length)
                return NULL;
        *oid_string = '\0';
        oid_out_len = 0;
-       sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, 1,
+       sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, TRUE,
            oid, oid_length);
        result_len += strlen(oid_string) + 3;
 #endif
@@ -297,8 +299,8 @@ format_oid(subid_t *oid, guint oid_length)
 
 /* returns the decoded (can be NULL) and non_decoded OID strings,
    returned pointers shall be freed by the caller */
-void 
-new_format_oid(subid_t *oid, guint oid_length, 
+void
+new_format_oid(subid_t *oid, guint oid_length,
               gchar **non_decoded, gchar **decoded)
 {
        int non_decoded_len;
@@ -316,12 +318,17 @@ new_format_oid(subid_t *oid, guint oid_length,
         * length of the result string.
         */
 
+       /*
+        * XXX - if we convert this to ep_alloc(), make sure the fourth
+        * argument to sprint_realloc_objid() is FALSE.
+        */
+
        oid_string_len = 256;
        oid_string = malloc(oid_string_len);
        if (oid_string != NULL) {
                *oid_string = '\0';
                oid_out_len = 0;
-               sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, 1,
+               sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, TRUE,
                                     oid, oid_length);
        }
        *decoded = oid_string;
@@ -365,7 +372,7 @@ static const value_string snmp_engineid_format_vals[] = {
        { 0,    NULL }
 };
 
-/* 
+/*
  * SNMP Engine ID dissection according to RFC 3411 (SnmpEngineID TC)
  * or historic RFC 1910 (AgentID)
  */
@@ -386,7 +393,7 @@ dissect_snmp_engineid(proto_tree *tree, tvbuff_t *tvb, int offset, int len)
     /* 4-byte enterprise number/name */
     if (len_remain<4) return offset;
     enterpriseid = tvb_get_ntohl(tvb, offset);
-    if (conformance) 
+    if (conformance)
       enterpriseid -= 0x80000000; /* ignore first bit */
     proto_tree_add_uint(tree, hf_snmp_engineid_enterprise, tvb, offset, 4, enterpriseid);
     offset+=4;
@@ -453,13 +460,13 @@ dissect_snmp_engineid(proto_tree *tree, tvbuff_t *tvb, int offset, int len)
       case 128:
        /* most common enterprise-specific format: (ucd|net)-snmp random */
        if ((enterpriseid==2021)||(enterpriseid==8072)) {
-         proto_item_append_text(item, (enterpriseid==2021) ? ": UCD-SNMP Random" : ": Net-SNMP Random"); 
+         proto_item_append_text(item, (enterpriseid==2021) ? ": UCD-SNMP Random" : ": Net-SNMP Random");
          /* demystify: 4B random, 4B epoch seconds */
          if (len_remain==8) {
            proto_tree_add_item(tree, hf_snmp_engineid_data, tvb, offset, 4, FALSE);
            seconds = tvb_get_letohl(tvb, offset+4);
            ts.secs = seconds;
-           proto_tree_add_time_format(tree, hf_snmp_engineid_time, tvb, offset+4, 4, 
+           proto_tree_add_time_format(tree, hf_snmp_engineid_time, tvb, offset+4, 4,
                                   &ts, "Engine ID Data: Creation Time: %s",
                                   abs_time_secs_to_str(seconds));
            offset+=8;
@@ -637,8 +644,8 @@ dissect_snmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        guint32 tmp_length;
        gboolean tmp_ind;
 
-       /* 
-        * See if this looks like SNMP or not. if not, return 0 so 
+       /*
+        * See if this looks like SNMP or not. if not, return 0 so
         * ethereal can try som other dissector instead.
         */
        /* All SNMP packets are BER encoded and consist of a SEQUENCE
@@ -874,7 +881,7 @@ void proto_register_snmp(void) {
   /* Register protocol */
   proto_snmp = proto_register_protocol(PNAME, PSNAME, PFNAME);
   new_register_dissector("snmp", dissect_snmp, proto_snmp);
-  
+
   /* Register fields and subtrees */
   proto_register_field_array(proto_snmp, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
index 76b664c9ed608bd0f58a3c25d888651c57e83a22..1e60038be57c9b79896ca52e88277c98d5d5551e 100644 (file)
@@ -1309,7 +1309,7 @@ static guchar*format_asn_value (struct variable_list *variable, subid_t *variabl
   if (!variable->type)
     variable->type=mib_to_asn_type(subtree->type);
 
-  if (!sprint_realloc_by_type(&buf, &buf_len, &out_len, TRUE, variable, subtree->enums, subtree->hint, NULL))
+  if (!sprint_realloc_by_type(&buf, &buf_len, &out_len, FALSE, variable, subtree->enums, subtree->hint, NULL))
     g_snprintf(buf,SPRINT_MAX_LEN,"%s","sprint_realloc_by_type failed");
 
   return buf;
@@ -1340,10 +1340,10 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb,packet_info *pinfo, guint32 of
 
   subid_t *vb_oid;
   guint vb_oid_length;
+  proto_item *vb_pi;
 
   gchar *vb_display_string;
   gchar *vb_display_string2;
-  size_t returned_length, str_index = 0;
 
 #ifdef HAVE_NET_SNMP
   struct variable_list variable;
@@ -1475,17 +1475,12 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb,packet_info *pinfo, guint32 of
              * We stopped, due to a non-printable character, before we got
              * to the end of the string.
              */
-            vb_display_string = ep_alloc(4*vb_length);
-            returned_length = g_snprintf(vb_display_string, 4*vb_length, "%03u",
-               vb_octet_string[0]);
-           str_index += MIN(returned_length, 4*vb_length);
+            vb_pi = proto_tree_add_text(tree, tvb, vb_value_start, length,
+                                "Value: %s: ", vb_type_name);
+            proto_item_append_text(vb_pi, "%03u", vb_octet_string[0]);
             for (i = 1; i < vb_length; i++) {
-              returned_length = g_snprintf(&vb_display_string[str_index],
-               4*vb_length-str_index, ".%03u", vb_octet_string[i]);
-             str_index += MIN(returned_length, 4*vb_length-str_index);
+              proto_item_append_text(vb_pi, ".%03u", vb_octet_string[0]);
             }
-            proto_tree_add_text(tree, tvb, vb_value_start, length,
-                                "Value: %s: %s", vb_type_name, vb_display_string);
           } else {
             proto_tree_add_text(tree, tvb, vb_value_start, length,
                                 "Value: %s: %.*s", vb_type_name, (int)vb_length,
@@ -1506,7 +1501,7 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb,packet_info *pinfo, guint32 of
 
     case COPS_OBJECTID:
       /* XXX Redo this using dissect_ber_object_identifier when it returns tvb
-         or some other binary form of an OID */ 
+         or some other binary form of an OID */
       offset = start;
       offset = dissect_ber_identifier(pinfo, tree, tvb, offset, &class, &pc, &ber_tag);
       offset = dissect_ber_length(pinfo, tree, tvb, offset, &vb_length, &ind);
@@ -1517,9 +1512,9 @@ static int decode_cops_pr_asn1_data(tvbuff_t *tvb,packet_info *pinfo, guint32 of
       offset = offset + vb_length;
       length = offset - vb_value_start;
 
-/*      ret = asn1_oid_value_decode (&asn1, vb_length, &vb_oid, &vb_oid_length); 
+/*      ret = asn1_oid_value_decode (&asn1, vb_length, &vb_oid, &vb_oid_length);
       if (ret != ASN1_ERR_NOERROR)
-        return ret; 
+        return ret;
       length = asn1.offset - start;
 */
       if (tree) {
index 5bfbe33d630e7e62590b37c81942ac65626705c8..5b8e9405244c71b68f0f154fec1ffa77bad0f406 100644 (file)
@@ -568,7 +568,7 @@ static const value_string snmp_engineid_format_vals[] = {
        { 0,    NULL }
 };
 
-/* 
+/*
  * SNMP Engine ID dissection according to RFC 3411 (SnmpEngineID TC)
  * or historic RFC 1910 (AgentID)
  */
@@ -589,7 +589,7 @@ dissect_snmp_engineid(proto_tree *tree, tvbuff_t *tvb, int offset, int len)
     /* 4-byte enterprise number/name */
     if (len_remain<4) return offset;
     enterpriseid = tvb_get_ntohl(tvb, offset);
-    if (conformance) 
+    if (conformance)
       enterpriseid -= 0x80000000; /* ignore first bit */
     proto_tree_add_uint(tree, hf_snmp_engineid_enterprise, tvb, offset, 4, enterpriseid);
     offset+=4;
@@ -656,13 +656,13 @@ dissect_snmp_engineid(proto_tree *tree, tvbuff_t *tvb, int offset, int len)
       case 128:
        /* most common enterprise-specific format: (ucd|net)-snmp random */
        if ((enterpriseid==2021)||(enterpriseid==8072)) {
-         proto_item_append_text(item, (enterpriseid==2021) ? ": UCD-SNMP Random" : ": Net-SNMP Random"); 
+         proto_item_append_text(item, (enterpriseid==2021) ? ": UCD-SNMP Random" : ": Net-SNMP Random");
          /* demystify: 4B random, 4B epoch seconds */
          if (len_remain==8) {
            proto_tree_add_item(tree, hf_snmp_engineid_data, tvb, offset, 4, FALSE);
            seconds = tvb_get_letohl(tvb, offset+4);
            ts.secs = seconds;
-           proto_tree_add_time_format(tree, hf_snmp_engineid_time, tvb, offset+4, 4, 
+           proto_tree_add_time_format(tree, hf_snmp_engineid_time, tvb, offset+4, 4,
                                   &ts, "Engine ID Data: Creation Time: %s",
                                   abs_time_secs_to_str(seconds));
            offset+=8;
@@ -770,6 +770,8 @@ format_oid(subid_t *oid, guint oid_length)
         * length of the result string.
         *
         * XXX - check for "sprint_realloc_objid()" failure.
+        * XXX - if we convert this to ep_alloc(), make sure the fourth
+        * argument to sprint_realloc_objid() is FALSE.
         */
        oid_string_len = 256;
        oid_string = malloc(oid_string_len);
@@ -777,7 +779,7 @@ format_oid(subid_t *oid, guint oid_length)
                return NULL;
        *oid_string = '\0';
        oid_out_len = 0;
-       sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, 1,
+       sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, TRUE,
            oid, oid_length);
        result_len += strlen(oid_string) + 3;
 #endif
@@ -804,8 +806,8 @@ format_oid(subid_t *oid, guint oid_length)
 
 /* returns the decoded (can be NULL) and non_decoded OID strings,
    returned pointers shall be freed by the caller */
-void 
-new_format_oid(subid_t *oid, guint oid_length, 
+void
+new_format_oid(subid_t *oid, guint oid_length,
               gchar **non_decoded, gchar **decoded)
 {
        int non_decoded_len;
@@ -823,12 +825,17 @@ new_format_oid(subid_t *oid, guint oid_length,
         * length of the result string.
         */
 
+       /*
+        * XXX - if we convert this to ep_alloc(), make sure the fourth
+        * argument to sprint_realloc_objid() is FALSE.
+        */
+
        oid_string_len = 256;
        oid_string = malloc(oid_string_len);
        if (oid_string != NULL) {
                *oid_string = '\0';
                oid_out_len = 0;
-               sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, 1,
+               sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, TRUE,
                                     oid, oid_length);
        }
        *decoded = oid_string;
@@ -951,12 +958,17 @@ format_var(struct variable_list *variable, subid_t *variable_oid,
        /*
         * XXX - check for "sprint_realloc_objid()" failure.
         */
+
+       /*
+        * XXX - if we convert this to ep_alloc(), make sure the fourth
+        * argument to sprint_realloc_objid() is FALSE.
+        */
        buf_len = 256;
        buf = malloc(buf_len);
        if (buf != NULL) {
                *buf = '\0';
                out_len = 0;
-               sprint_realloc_value(&buf, &buf_len, &out_len, 1,
+               sprint_realloc_value(&buf, &buf_len, &out_len, TRUE,
                    variable_oid, variable_oid_length, variable);
        }
        return buf;
@@ -1158,7 +1170,7 @@ snmp_variable_decode(proto_tree *snmp_tree, packet_info *pinfo,
 
        case SNMP_OBJECTID:
                /* XXX Redo this using dissect_ber_object_identifier when
-                  it returns tvb or some other binary form of an OID */ 
+                  it returns tvb or some other binary form of an OID */
                oid_buf = tvb_get_ptr(asn1->tvb, vb_value_start, vb_length);
                vb_oid = g_malloc((vb_length+1) * sizeof(gulong));
                vb_oid_length = oid_to_subid_buf(oid_buf, vb_length, vb_oid, ((vb_length+1) * sizeof(gulong)));
@@ -1327,7 +1339,7 @@ dissect_common_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
                                proto_tree_add_text(tree, tvb, offset,
                                    length, "Non-repeaters: %u", error_status);
                        } else {
-                               proto_tree_add_uint(tree, 
+                               proto_tree_add_uint(tree,
                                                    hf_snmp_error_status,
                                                    tvb, offset,
                                                    length, error_status);
@@ -1518,36 +1530,36 @@ dissect_common_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
 
                  new_format_oid(variable_oid, variable_oid_length,
                                 &non_decoded_oid, &decoded_oid);
-                 
+
                  if (display_oid && check_col(pinfo->cinfo, COL_INFO)) {
-                   col_append_fstr(pinfo->cinfo, COL_INFO, 
-                                   " %s", 
+                   col_append_fstr(pinfo->cinfo, COL_INFO,
+                                   " %s",
                                    (decoded_oid == NULL) ? non_decoded_oid :
                                    decoded_oid);
                  }
-                 
+
                  if (tree) {
                    if (decoded_oid) {
                      proto_tree_add_string_format(tree, hf_snmp_oid,
-                                                  tvb, offset, 
-                                                  sequence_length, 
+                                                  tvb, offset,
+                                                  sequence_length,
                                                   decoded_oid,
-                                                  "Object identifier %d: %s (%s)", 
-                                                  vb_index, 
+                                                  "Object identifier %d: %s (%s)",
+                                                  vb_index,
                                                   non_decoded_oid,
                                                   decoded_oid);
                      /* add also the non decoded oid string */
                      proto_tree_add_string_hidden(tree, hf_snmp_oid,
-                                                  tvb, offset, 
+                                                  tvb, offset,
                                                   sequence_length,
                                                   non_decoded_oid);
                    } else {
                      proto_tree_add_string_format(tree, hf_snmp_oid,
-                                                  tvb, offset, 
-                                                  sequence_length, 
+                                                  tvb, offset,
+                                                  sequence_length,
                                                   non_decoded_oid,
-                                                  "Object identifier %d: %s", 
-                                                  vb_index, 
+                                                  "Object identifier %d: %s",
+                                                  vb_index,
                                                   non_decoded_oid);
                    }
                  }
@@ -2519,8 +2531,8 @@ dissect_snmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        guint32 tmp_length;
        gboolean tmp_ind;
 
-       /* 
-        * See if this looks like SNMP or not. if not, return 0 so 
+       /*
+        * See if this looks like SNMP or not. if not, return 0 so
         * ethereal can try som other dissector instead.
         */
        /* All SNMP packets are BER encoded and consist of a SEQUENCE
index 5e07410697acdad830fb31686b5513f634b6be56..3498aac645d85ad99249688adad53ce1a8a57e3a 100644 (file)
@@ -76,9 +76,11 @@ typedef struct _emem_chunk_t {
        unsigned int    amount_free;
        unsigned int    free_offset;
        char *buf;
+#if ! defined(EP_DEBUG_FREE) && ! defined(SE_DEBUG_FREE)
        unsigned int    c_count;
        void            *canary[EMEM_ALLOCS_PER_CHUNK];
        guint8          cmp_len[EMEM_ALLOCS_PER_CHUNK];
+#endif
 } emem_chunk_t;
 
 typedef struct _emem_header_t {