From 34e413f66d037f37347bf257b06b6cd1898e2204 Mon Sep 17 00:00:00 2001 From: Kevin Cox Date: Fri, 25 Jul 2014 12:29:04 -0400 Subject: 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/value_string.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'epan/value_string.c') 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]"; } /* -- cgit v1.2.3