diff options
author | Guy Harris <guy@alum.mit.edu> | 2012-01-25 23:03:33 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2012-01-25 23:03:33 +0000 |
commit | 6f59700722eeba702a7dfdff6b84f5940744996b (patch) | |
tree | cbf2428dc4c8c7651e4fd812cc80162714d9b6f0 | |
parent | 3d3346bc7e8fc45a1f7cbbaf23de05a64f0d8f52 (diff) |
Fix usage of g_ascii_strdown() and g_ascii_strup() - they do *not*
modify the string in place, they return a g_mallocated modified version
of the string passed into them.
svn path=/trunk/; revision=40727
-rw-r--r-- | epan/uat.h | 5 | ||||
-rw-r--r-- | epan/wslua/wslua_proto.c | 20 |
2 files changed, 14 insertions, 11 deletions
diff --git a/epan/uat.h b/epan/uat.h index 90a8cde9fa..53806ab9fa 100644 --- a/epan/uat.h +++ b/epan/uat.h @@ -511,7 +511,10 @@ static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out #define UAT_PROTO_DEF(basename, field_name, dissector_field, name_field, rec_t) \ static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* u1 _U_, const void* u2 _U_) {\ if (len) { \ - ((rec_t*)rec)->name_field = g_strndup(buf,len); g_ascii_strdown(((rec_t*)rec)->name_field, -1); g_strchug(((rec_t*)rec)->name_field); \ + gchar *tmp = g_strndup(buf,len); \ + ((rec_t*)rec)->name_field = g_ascii_strdown(tmp, -1); \ + g_free(tmp); \ + g_strchug(((rec_t*)rec)->name_field); \ ((rec_t*)rec)->dissector_field = find_dissector(((rec_t*)rec)->name_field); \ } else { \ ((rec_t*)rec)->dissector_field = find_dissector("data"); \ diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index d95b5b7500..1cd6f8a939 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -1140,17 +1140,18 @@ WSLUA_CONSTRUCTOR Proto_new(lua_State* L) { const gchar* desc = luaL_checkstring(L,WSLUA_ARG_Proto_new_DESC); if ( name ) { - gchar* loname_a = ep_strdup(name); - g_ascii_strdown(loname_a, -1); - if ( proto_get_id_by_filter_name(loname_a) > 0 ) { + gchar* loname_a; + int proto_id; + + loname_a = g_ascii_strdown(name, -1); + proto_id = proto_get_id_by_filter_name(loname_a); + g_free(loname_a); + if ( proto_id > 0 ) { WSLUA_ARG_ERROR(Proto_new,NAME,"there cannot be two protocols with the same name"); } else { Proto proto = g_malloc(sizeof(wslua_proto_t)); - gchar* loname = g_strdup(name); - gchar* hiname = g_strdup(name); - - g_ascii_strdown(loname, -1); - g_ascii_strup(hiname, -1); + gchar* loname = g_ascii_strdown(name, -1); + gchar* hiname = g_ascii_strup(name, -1); proto->name = hiname; proto->desc = g_strdup(desc); @@ -1236,8 +1237,7 @@ static int Proto_set_dissector(lua_State* L) { if (lua_isfunction(L,3)) { /* insert the dissector into the dissectors table */ - gchar* loname = g_strdup(proto->name); - g_ascii_strdown(loname, -1); + gchar* loname = g_ascii_strdown(proto->name, -1); lua_rawgeti(L, LUA_REGISTRYINDEX, lua_dissectors_table_ref); lua_replace(L, 1); |