aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-03-07 20:09:21 -0800
committerGuy Harris <guy@alum.mit.edu>2018-03-08 04:10:04 +0000
commit695fbb9be0122e280755c11b9e0b89e9e256875b (patch)
treea5ab26e753a619c11ce753f62e66c2f60eae803f
parente7cf995b1e0a9b434782adf0e2ee40bfb721aac2 (diff)
Squelch some casting-away-constness warnings.
In true_false_string_from_table(), keep the pointers to the "true" and "false" strings in local non-const pointer variables, so we can free them without a complaint. Only when we're finished, and have valid "true" and "false" strings, do we allocate the true_false_string structure and fill it in with those pointers. Change-Id: I6eb3ee46bdc47bf42d6e913c72884f0eac22997e Reviewed-on: https://code.wireshark.org/review/26353 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--epan/wslua/wslua_proto_field.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/epan/wslua/wslua_proto_field.c b/epan/wslua/wslua_proto_field.c
index e38fefdcff..65de1adb98 100644
--- a/epan/wslua/wslua_proto_field.c
+++ b/epan/wslua/wslua_proto_field.c
@@ -252,6 +252,8 @@ static val64_string* val64_string_from_table(lua_State* L, int idx) {
static true_false_string* true_false_string_from_table(lua_State* L, int idx) {
true_false_string* tfs;
+ gchar *true_string;
+ gchar *false_string;
if (lua_isnil(L,idx)) {
return NULL;
@@ -260,26 +262,23 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) {
return NULL;
}
- tfs = (true_false_string *) g_malloc(sizeof(true_false_string));
- tfs->true_string = g_strdup("True");
- tfs->false_string = g_strdup("False");
+ true_string = g_strdup("True");
+ false_string = g_strdup("False");
lua_pushnil(L);
while (lua_next(L, idx)) {
if (! lua_isnumber(L,-2)) {
- g_free ((gchar *)tfs->true_string);
- g_free ((gchar *)tfs->false_string);
- g_free (tfs);
+ g_free (true_string);
+ g_free (false_string);
luaL_argerror(L,idx,"All keys of a table used as true_false_string must be integers");
return NULL;
}
if (! lua_isstring(L,-1)) {
- g_free ((gchar *)tfs->true_string);
- g_free ((gchar *)tfs->false_string);
- g_free (tfs);
+ g_free (true_string);
+ g_free (false_string);
luaL_argerror(L,idx,"All values of a table used as true_false_string must be strings");
return NULL;
}
@@ -287,17 +286,16 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) {
/* Arrays in LUA start with index number 1 */
switch (lua_tointeger(L,-2)) {
case 1:
- g_free((gchar *)tfs->true_string);
- tfs->true_string = g_strdup(lua_tostring(L,-1));
+ g_free(true_string);
+ true_string = g_strdup(lua_tostring(L,-1));
break;
case 2:
- g_free((gchar *)tfs->false_string);
- tfs->false_string = g_strdup(lua_tostring(L,-1));
+ g_free(false_string);
+ false_string = g_strdup(lua_tostring(L,-1));
break;
default:
- g_free ((gchar *)tfs->true_string);
- g_free ((gchar *)tfs->false_string);
- g_free (tfs);
+ g_free (true_string);
+ g_free (false_string);
luaL_argerror(L,idx,"The true_false_string table can have maximum two strings with key value 1 and 2");
return NULL;
}
@@ -305,6 +303,10 @@ static true_false_string* true_false_string_from_table(lua_State* L, int idx) {
lua_pop(L, 1);
}
+ tfs = (true_false_string *) g_malloc(sizeof(true_false_string));
+ tfs->true_string = true_string;
+ tfs->false_string = false_string;
+
return tfs;
}