From 34e413f66d037f37347bf257b06b6cd1898e2204 Mon Sep 17 00:00:00 2001 From: Kevin Cox Date: Fri, 25 Jul 2014 12:29:04 -0400 Subject: [PATCH] Make value_string_ext const-correct. There is still some const-incorrect usage of them but those can be ironed out after this change has been made. Change-Id: Iba0631c804bdab34d7c0232b49967130e3370488 Reviewed-on: https://code.wireshark.org/review/3199 Petri-Dish: Pascal Quantin Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/dissectors/packet-diameter.c | 8 ++++---- epan/dissectors/packet-etch.c | 2 +- epan/dissectors/packet-usb-video.c | 12 ++++++------ epan/proto.c | 6 +++--- epan/value_string.c | 31 ++++++++++++------------------ epan/value_string.h | 20 +++++++++---------- rawshark.c | 4 ++-- ui/gtk/dfilter_expr_dlg.c | 2 +- 8 files changed, 39 insertions(+), 46 deletions(-) diff --git a/epan/dissectors/packet-diameter.c b/epan/dissectors/packet-diameter.c index b73856950f..a194b3c7b9 100644 --- a/epan/dissectors/packet-diameter.c +++ b/epan/dissectors/packet-diameter.c @@ -126,7 +126,7 @@ typedef const char *(*diam_avp_dissector_t)(diam_ctx_t *, diam_avp_t *, tvbuff_t typedef struct _diam_vnd_t { guint32 code; GArray *vs_avps; - const value_string_ext *vs_avps_ext; + value_string_ext *vs_avps_ext; GArray *vs_cmds; } diam_vnd_t; @@ -1324,7 +1324,7 @@ alnumerize(char *name) static guint reginfo(int *hf_ptr, const char *name, const char *abbr, const char *desc, - enum ftenum ft, field_display_e base, const value_string_ext *vs_ext, + enum ftenum ft, field_display_e base, value_string_ext *vs_ext, guint32 mask) { hf_register_info hf; @@ -1350,7 +1350,7 @@ reginfo(int *hf_ptr, const char *name, const char *abbr, const char *desc, static void basic_avp_reginfo(diam_avp_t *a, const char *name, enum ftenum ft, - field_display_e base, const value_string_ext *vs_ext) + field_display_e base, value_string_ext *vs_ext) { hf_register_info hf; gint *ettp = &(a->ett); @@ -1481,7 +1481,7 @@ build_simple_avp(const avp_type_t *type, guint32 code, diam_vnd_t *vendor, const char *name, const value_string *vs, void *data _U_) { diam_avp_t *a; - const value_string_ext *vs_ext = NULL; + value_string_ext *vs_ext = NULL; field_display_e base; guint i = 0; diff --git a/epan/dissectors/packet-etch.c b/epan/dissectors/packet-etch.c index aa0d6b8b95..b86f7d1a46 100644 --- a/epan/dissectors/packet-etch.c +++ b/epan/dissectors/packet-etch.c @@ -174,7 +174,7 @@ static int read_value(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree * (Code based upon code in packet-diameter.c) */ static GArray *gbl_symbols_array = NULL; -static const value_string_ext *gbl_symbols_vs_ext = NULL; +static value_string_ext *gbl_symbols_vs_ext = NULL; static void gbl_symbols_new(void) diff --git a/epan/dissectors/packet-usb-video.c b/epan/dissectors/packet-usb-video.c index 75bcddd4d0..71f81773c8 100644 --- a/epan/dissectors/packet-usb-video.c +++ b/epan/dissectors/packet-usb-video.c @@ -1582,12 +1582,12 @@ dissect_usb_vid_probe(proto_tree *parent_tree, tvbuff_t *tvb, int offset) * * @return Table describing control selectors for the specified entity (may be NULL) */ -static const value_string_ext* +static value_string_ext* get_control_selector_values(guint8 entity_id, usb_conv_info_t *usb_conv_info) { - video_conv_info_t *video_conv_info; - video_entity_t *entity = NULL; - const value_string_ext *selectors = NULL; + video_conv_info_t *video_conv_info; + video_entity_t *entity = NULL; + value_string_ext *selectors = NULL; if (usb_conv_info == NULL) return NULL; @@ -1652,8 +1652,8 @@ get_control_selector_values(guint8 entity_id, usb_conv_info_t *usb_conv_info) static const gchar* get_control_selector_name(guint8 entity_id, guint8 control_sel, usb_conv_info_t *usb_conv_info) { - const gchar *control_name = NULL; - const value_string_ext *selectors = NULL; + const gchar *control_name = NULL; + value_string_ext *selectors = NULL; selectors = get_control_selector_values(entity_id, usb_conv_info); diff --git a/epan/proto.c b/epan/proto.c index 059e18a495..f3982a6a3f 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -6036,7 +6036,7 @@ hf_try_val_to_str(guint32 value, const header_field_info *hfinfo) return try_rval_to_str(value, (const range_string *) hfinfo->strings); if (hfinfo->display & BASE_EXT_STRING) - return try_val_to_str_ext(value, (const value_string_ext *) hfinfo->strings); + return try_val_to_str_ext(value, (value_string_ext *) hfinfo->strings); if (hfinfo->display & BASE_VAL64_STRING) return try_val64_to_str(value, (const val64_string *) hfinfo->strings); @@ -6795,7 +6795,7 @@ proto_registrar_dump_values(void) if (hfinfo->display & BASE_RANGE_STRING) { range = (const range_string *)hfinfo->strings; } else if (hfinfo->display & BASE_EXT_STRING) { - vals = VALUE_STRING_EXT_VS_P((const value_string_ext *)hfinfo->strings); + vals = VALUE_STRING_EXT_VS_P((value_string_ext *)hfinfo->strings); } else if (hfinfo->display & BASE_VAL64_STRING) { vals64 = (const val64_string *)hfinfo->strings; } else { @@ -6810,7 +6810,7 @@ proto_registrar_dump_values(void) /* Print value strings? */ if (vals) { if (hfinfo->display & BASE_EXT_STRING) { - const value_string_ext *vse_p = (const value_string_ext *)hfinfo->strings; + value_string_ext *vse_p = (value_string_ext *)hfinfo->strings; if (!value_string_ext_validate(vse_p)) { g_warning("Invalid value_string_ext ptr for: %s", hfinfo->abbrev); continue; diff --git a/epan/value_string.c b/epan/value_string.c index 9c4fbf8f28..ea4a9a9db9 100644 --- a/epan/value_string.c +++ b/epan/value_string.c @@ -239,7 +239,7 @@ str_to_val_idx(const gchar *val, const value_string *vs) * required {0, NULL} terminating entry of the array. * Returns a pointer to an epan-scoped'd and initialized value_string_ext * struct. */ -const value_string_ext * +value_string_ext * value_string_ext_new(const value_string *vs, guint vs_tot_num_entries, const gchar *vs_name) { @@ -272,7 +272,7 @@ value_string_ext_free(const value_string_ext *vse) /* Like try_val_to_str for extended value strings */ const gchar * -try_val_to_str_ext(const guint32 val, const value_string_ext *vse) +try_val_to_str_ext(const guint32 val, value_string_ext *vse) { if (vse) { const value_string *vs = vse->_vs_match2(val, vse); @@ -287,7 +287,7 @@ try_val_to_str_ext(const guint32 val, const value_string_ext *vse) /* Like try_val_to_str_idx for extended value strings */ const gchar * -try_val_to_str_idx_ext(const guint32 val, const value_string_ext *vse, gint *idx) +try_val_to_str_idx_ext(const guint32 val, value_string_ext *vse, gint *idx) { if (vse) { const value_string *vs = vse->_vs_match2(val, vse); @@ -302,7 +302,7 @@ try_val_to_str_idx_ext(const guint32 val, const value_string_ext *vse, gint *idx /* Like val_to_str for extended value strings */ const gchar * -val_to_str_ext(const guint32 val, const value_string_ext *vse, const char *fmt) +val_to_str_ext(const guint32 val, value_string_ext *vse, const char *fmt) { const gchar *ret; @@ -317,7 +317,7 @@ val_to_str_ext(const guint32 val, const value_string_ext *vse, const char *fmt) /* Like val_to_str_const for extended value strings */ const gchar * -val_to_str_ext_const(const guint32 val, const value_string_ext *vse, +val_to_str_ext_const(const guint32 val, value_string_ext *vse, const char *unknown_str) { const gchar *ret; @@ -333,7 +333,7 @@ val_to_str_ext_const(const guint32 val, const value_string_ext *vse, /* Fallback linear matching algorithm for extended value strings */ static const value_string * -_try_val_to_str_linear(const guint32 val, const value_string_ext *vse) +_try_val_to_str_linear(const guint32 val, value_string_ext *vse) { const value_string *vs_p = vse->_vs_p; guint i; @@ -346,7 +346,7 @@ _try_val_to_str_linear(const guint32 val, const value_string_ext *vse) /* Constant-time matching algorithm for contiguous extended value strings */ static const value_string * -_try_val_to_str_index(const guint32 val, const value_string_ext *vse) +_try_val_to_str_index(const guint32 val, value_string_ext *vse) { guint i; @@ -360,7 +360,7 @@ _try_val_to_str_index(const guint32 val, const value_string_ext *vse) /* log(n)-time matching algorithm for sorted extended value strings */ static const value_string * -_try_val_to_str_bsearch(const guint32 val, const value_string_ext *vse) +_try_val_to_str_bsearch(const guint32 val, value_string_ext *vse) { guint low, i, max; guint32 item; @@ -387,17 +387,8 @@ _try_val_to_str_bsearch(const guint32 val, const value_string_ext *vse) * - Verifies that the value_string is terminated by {0, NULL} */ const value_string * -_try_val_to_str_ext_init(const guint32 val, const value_string_ext *a_vse) +_try_val_to_str_ext_init(const guint32 val, value_string_ext *vse) { - /* Cast away the constness! - * It's better if the prototype for this function matches the other - * _try_val_to_str_* functions (so we don't have to cast it when storing it - * in _try_val_to_str so the compiler will notice if the prototypes get out - * of sync), but the init function is unique in that it does actually - * modify the vse. - */ - value_string_ext *vse = (value_string_ext *)a_vse; - const value_string *vs_p = vse->_vs_p; const guint vs_num_entries = vse->_vs_num_entries; @@ -616,13 +607,15 @@ value_string_ext_validate(const value_string_ext *vse) const gchar * value_string_ext_match_type_str(const value_string_ext *vse) { + if (vse->_vs_match2 == _try_val_to_str_ext_init) + return "[Not Initialized]"; if (vse->_vs_match2 == _try_val_to_str_linear) return "[Linear Search]"; if (vse->_vs_match2 == _try_val_to_str_bsearch) return "[Binary Search]"; if (vse->_vs_match2 == _try_val_to_str_index) return "[Direct (indexed) Access]"; - return "[Match Type not initialized or invalid]"; + return "[Invalid]"; } /* diff --git a/epan/value_string.h b/epan/value_string.h index c7b57f9a89..04f17c8b0c 100644 --- a/epan/value_string.h +++ b/epan/value_string.h @@ -164,17 +164,17 @@ str_to_val_idx(const gchar *val, const value_string *vs); /* EXTENDED VALUE TO STRING MATCHING */ -struct _value_string_ext; -typedef const value_string *(*_value_string_match2_t)(const guint32, const struct _value_string_ext *); +typedef struct _value_string_ext value_string_ext; +typedef const value_string *(*_value_string_match2_t)(const guint32, value_string_ext*); -typedef struct _value_string_ext { +struct _value_string_ext { _value_string_match2_t _vs_match2; guint32 _vs_first_value; /* first value of the value_string array */ guint _vs_num_entries; /* number of entries in the value_string array */ /* (excluding final {0, NULL}) */ const value_string *_vs_p; /* the value string array address */ const gchar *_vs_name; /* vse "Name" (for error messages) */ -} value_string_ext; +}; #define VALUE_STRING_EXT_VS_P(x) (x)->_vs_p #define VALUE_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries @@ -182,11 +182,11 @@ typedef struct _value_string_ext { WS_DLL_PUBLIC const value_string * -_try_val_to_str_ext_init(const guint32 val, const value_string_ext *vse); +_try_val_to_str_ext_init(const guint32 val, value_string_ext *vse); #define VALUE_STRING_EXT_INIT(x) { _try_val_to_str_ext_init, 0, G_N_ELEMENTS(x)-1, x, #x } WS_DLL_PUBLIC -const value_string_ext * +value_string_ext * value_string_ext_new(const value_string *vs, guint vs_tot_num_entries, const gchar *vs_name); WS_DLL_PUBLIC @@ -195,20 +195,20 @@ value_string_ext_free(const value_string_ext *vse); WS_DLL_PUBLIC const gchar * -val_to_str_ext(const guint32 val, const value_string_ext *vs, const char *fmt) +val_to_str_ext(const guint32 val, value_string_ext *vs, const char *fmt) G_GNUC_PRINTF(3, 0); WS_DLL_PUBLIC const gchar * -val_to_str_ext_const(const guint32 val, const value_string_ext *vs, const char *unknown_str); +val_to_str_ext_const(const guint32 val, value_string_ext *vs, const char *unknown_str); WS_DLL_PUBLIC const gchar * -try_val_to_str_ext(const guint32 val, const value_string_ext *vse); +try_val_to_str_ext(const guint32 val, value_string_ext *vse); WS_DLL_PUBLIC const gchar * -try_val_to_str_idx_ext(const guint32 val, const value_string_ext *vse, gint *idx); +try_val_to_str_idx_ext(const guint32 val, value_string_ext *vse, gint *idx); /* STRING TO STRING MATCHING */ diff --git a/rawshark.c b/rawshark.c index 39503711a1..53ad1ac022 100644 --- a/rawshark.c +++ b/rawshark.c @@ -1391,7 +1391,7 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index) if (hfinfo->display & BASE_RANGE_STRING) { g_string_append(label_s, rval_to_str_const(svalue, RVALS(hfinfo->strings), "Unknown")); } else if (hfinfo->display & BASE_EXT_STRING) { - g_string_append(label_s, val_to_str_ext_const(svalue, (const value_string_ext *) hfinfo->strings, "Unknown")); + g_string_append(label_s, val_to_str_ext_const(svalue, (value_string_ext *) hfinfo->strings, "Unknown")); } else { g_string_append(label_s, val_to_str_const(svalue, cVALS(hfinfo->strings), "Unknown")); } @@ -1411,7 +1411,7 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index) if (!hfinfo->bitmask && hfinfo->display & BASE_RANGE_STRING) { g_string_append(label_s, rval_to_str_const(uvalue, RVALS(hfinfo->strings), "Unknown")); } else if (hfinfo->display & BASE_EXT_STRING) { - g_string_append(label_s, val_to_str_ext_const(uvalue, (const value_string_ext *) hfinfo->strings, "Unknown")); + g_string_append(label_s, val_to_str_ext_const(uvalue, (value_string_ext *) hfinfo->strings, "Unknown")); } else { g_string_append(label_s, val_to_str_const(uvalue, cVALS(hfinfo->strings), "Unknown")); } diff --git a/ui/gtk/dfilter_expr_dlg.c b/ui/gtk/dfilter_expr_dlg.c index 39ce543e5f..1e7ae8a7fd 100644 --- a/ui/gtk/dfilter_expr_dlg.c +++ b/ui/gtk/dfilter_expr_dlg.c @@ -194,7 +194,7 @@ field_select_row_cb(GtkTreeSelection *sel, gpointer tree) ! ((hfinfo->display & FIELD_DISPLAY_E_MASK) == BASE_CUSTOM)) { const value_string *vals = (const value_string *)hfinfo->strings; if (hfinfo->display & BASE_EXT_STRING) - vals = VALUE_STRING_EXT_VS_P((const value_string_ext *)vals); + vals = VALUE_STRING_EXT_VS_P((value_string_ext *)vals); build_enum_values(value_list_scrolled_win, value_list, vals); } else gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(value_list))));