diff --git a/epan/dissectors/packet-tpncp.c b/epan/dissectors/packet-tpncp.c index 4012b54a30..a9681d1eb3 100644 --- a/epan/dissectors/packet-tpncp.c +++ b/epan/dissectors/packet-tpncp.c @@ -118,7 +118,7 @@ static value_string tpncp_events_id_vals[MAX_TPNCP_DB_SIZE]; static value_string tpncp_enums_id_vals[MAX_ENUMS_NUM][MAX_ENUM_ENTRIES]; static gchar *tpncp_enums_name_vals[MAX_ENUMS_NUM]; -static gint hf_size = 1; +static gint hf_size = 0; static gint hf_allocated = 0; static hf_register_info *hf = NULL; @@ -549,7 +549,7 @@ get_enum_name_val(const gchar *enum_name) static gboolean add_hf(hf_register_info *hf_entr) { - if (hf_size > hf_allocated) { + if (hf_size >= hf_allocated) { void *newbuf; hf_allocated += 1024; newbuf = wmem_realloc(wmem_epan_scope(), hf, hf_allocated * sizeof (hf_register_info)); @@ -557,7 +557,7 @@ static gboolean add_hf(hf_register_info *hf_entr) return FALSE; hf = (hf_register_info *) newbuf; } - memcpy(hf + hf_size - 1, hf_entr, sizeof (hf_register_info)); + memcpy(hf + hf_size, hf_entr, sizeof (hf_register_info)); hf_size++; return TRUE; } @@ -688,18 +688,17 @@ init_tpncp_data_fields_info(tpncp_data_field_info *data_fields_info, FILE *file) void *newbuf; /* Register non-standard data should be done only once. */ - hf_allocated = hf_size + (int) array_length(hf_tpncp) - 1; + hf_allocated = hf_size + (int) array_length(hf_tpncp); newbuf = wmem_realloc(wmem_epan_scope(), hf, hf_allocated * sizeof (hf_register_info)); if (!newbuf) return -1; hf = (hf_register_info *) newbuf; for (idx = 0; idx < array_length(hf_tpncp); idx++) { - memcpy(hf + (hf_size - 1), hf_tpncp + idx, sizeof (hf_register_info)); + memcpy(hf + hf_size, hf_tpncp + idx, sizeof (hf_register_info)); hf_size++; } was_registered = TRUE; - } else - hf_size++; + } is_address_family = FALSE; ip_addr_field = 0; @@ -709,10 +708,8 @@ init_tpncp_data_fields_info(tpncp_data_field_info *data_fields_info, FILE *file) special_type = TPNCP_NORMAL; since = 0; snprintf(entry_copy, MAX_TPNCP_DB_ENTRY_LEN, "%s", tpncp_db_entry); - if (!strncmp(tpncp_db_entry, "#####", 5)) { - hf_size--; + if (!strncmp(tpncp_db_entry, "#####", 5)) break; - } /* Default to decimal display type */ hf_entr.hfinfo.display = BASE_DEC;