Wireshark-dev: Re: [Wireshark-dev] [PATCH] Fixup for a segfault with gtk1.2
From: Sebastien Tandel <sebastien@xxxxxxxxx>
Date: Sun, 04 Feb 2007 02:23:11 +0100
Hi, >> I was wondering whether it couldn't be easier to replace the >> g_strsplit of gtk1.2 by the one implemented in gtk2. It will be far >> more easier to avoid problems in the current dissectors and in the >> future. >> >> Write a new header file (w_strsplit.h) which defines a macro replacing >> the string g_strsplit by w_strsplit and implements the function as a >> copy of g_strsplit defined in gtk2. It should be defined only if using >> gtk1.2 of course ... Include the header w_strplsit.h in each file >> using g_strsplit ... and the work is done. No more headache ! >> >> What do you think? >> > > This is probably the best approach as trying to fix every place the > broken g_strsplit occurs (while compiled for GTK1) is very troublesome. > If you have time, could you work on a patch to try this out? > Here are two patches to resolve conflicts for g_strsplit with glib2 and glib1.2. The first one (ws_strsplit.diff) creates ws_strsplit.[c,h] in the epan repository but I'm not sure this is the right place as potentially used anywhere in the code of wireshark. The second patch (ws_strsplit-inclusion.diff) includes ws_strsplit.h in C files using g_strsplit. I've also deleted the specific code to gtk1.2 in epan/stats_tree.c Regards, Sebastien Tandel
Index: epan/ws_strsplit.c =================================================================== --- epan/ws_strsplit.c (révision 0) +++ epan/ws_strsplit.c (révision 0) @@ -0,0 +1,81 @@ +/* ws_strsplit.c + * String Split utility function + * implemented to get rid of problems between gtk1.2 and gtk2 versions of g_strsplit. + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@xxxxxxxxxxxxx> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#if GLIB_MAJOR_VERSION < 2 +#include <glib.h> +#include <string.h> + +gchar** ws_strsplit ( const gchar *string, + const gchar *delimiter, + gint max_tokens) +{ + GSList *string_list = NULL, *slist; + gchar **str_array, *s; + guint n = 0; + const gchar *remainder; + + g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (delimiter != NULL, NULL); + g_return_val_if_fail (delimiter[0] != '\0', NULL); + + if (max_tokens < 1) + max_tokens = G_MAXINT; + + remainder = string; + s = strstr (remainder, delimiter); + if (s) { + gsize delimiter_len = strlen (delimiter); + + while (--max_tokens && s) { + gsize len; + gchar *new_string; + + len = s - remainder; + new_string = g_new (gchar, len + 1); + strncpy (new_string, remainder, len); + new_string[len] = 0; + string_list = g_slist_prepend (string_list, new_string); + n++; + remainder = s + delimiter_len; + s = strstr (remainder, delimiter); + } + } + if (*string) { + n++; + string_list = g_slist_prepend (string_list, g_strdup (remainder)); + } + + str_array = g_new (gchar*, n + 1); + + str_array[n--] = NULL; + for (slist = string_list; slist; slist = slist->next) + str_array[n--] = slist->data; + + g_slist_free (string_list); + + return str_array; +} + +#endif /* GLIB_MAJOR_VERSION */ Index: epan/ws_strsplit.h =================================================================== --- epan/ws_strsplit.h (révision 0) +++ epan/ws_strsplit.h (révision 0) @@ -0,0 +1,40 @@ +/* ws_strsplit.h + * String Split utility function + * implemented to get rid of problems between gtk1.2 and gtk2 versions of g_strsplit. + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@xxxxxxxxxxxxx> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __WS_STRSPLIT_H__ +#define __WS_STRSPLIT_H__ + +#if GLIB_MAJOR_VERSION < 2 + +#define g_strsplit(s, d, t) ws_strsplit(s, d, t) + +gchar ** ws_strsplit (const gchar *string, + const gchar *delimiter, + gint max_tokens); + +#endif /* GLIB_MAJOR_VERSION */ + +#endif /* __WS_STRSPLIT_H__ */ + Index: epan/Makefile.common =================================================================== --- epan/Makefile.common (révision 20702) +++ epan/Makefile.common (copie de travail) @@ -92,6 +92,7 @@ uat_load.c \ unicode-utils.c \ value_string.c \ + ws_strsplit.c \ xdlc.c \ xmlstub.c @@ -191,6 +192,7 @@ uat-int.h \ unicode-utils.h \ value_string.h \ + ws_strsplit.h \ x264_prt_id.h \ xdlc.h \ xmlstub.h
Index: gtk/font_utils.c =================================================================== --- gtk/font_utils.c (révision 20702) +++ gtk/font_utils.c (copie de travail) @@ -32,6 +32,7 @@ #include <stdio.h> #include <epan/packet.h> +#include <epan/ws_strsplit.h> #ifdef _WIN32 #include <windows.h> Index: gtk/voip_calls.c =================================================================== --- gtk/voip_calls.c (révision 20702) +++ gtk/voip_calls.c (copie de travail) @@ -61,6 +61,7 @@ #include <epan/dissectors/packet-t38.h> #include <epan/conversation.h> #include <epan/rtp_pt.h> +#include <epan/ws_strsplit.h> #include "alert_box.h" #include "simple_dialog.h" Index: gtk/webbrowser.c =================================================================== --- gtk/webbrowser.c (révision 20702) +++ gtk/webbrowser.c (copie de travail) @@ -35,6 +35,7 @@ #include <gtk/gtk.h> #include <epan/filesystem.h> +#include <epan/ws_strsplit.h> #include <epan/prefs.h> #include "webbrowser.h" Index: util.c =================================================================== --- util.c (révision 20702) +++ util.c (copie de travail) @@ -39,6 +39,7 @@ #include <epan/address.h> #include <epan/addr_resolv.h> +#include <epan/ws_strsplit.h> #include "util.h" Index: plugins/mate/mate_setup.c =================================================================== --- plugins/mate/mate_setup.c (révision 20702) +++ plugins/mate/mate_setup.c (copie de travail) @@ -25,6 +25,7 @@ */ #include "mate.h" +#include <epan/ws_strsplit.h> /* the current mate_config */ static mate_config* matecfg = NULL; Index: plugins/mate/mate_util.c =================================================================== --- plugins/mate/mate_util.c (révision 20702) +++ plugins/mate/mate_util.c (copie de travail) @@ -28,6 +28,7 @@ #include "mate.h" #include "mate_util.h" #include <wiretap/file_util.h> +#include <epan/ws_strsplit.h> /*************************************************************************** * dbg_print Index: plugins/mate/mate_grammar.lemon =================================================================== --- plugins/mate/mate_grammar.lemon (révision 20702) +++ plugins/mate/mate_grammar.lemon (copie de travail) @@ -28,6 +28,7 @@ #include "mate.h" #include "mate_grammar.h" +#include <epan/ws_strsplit.h> #define DUMMY void* Index: epan/stats_tree.c =================================================================== --- epan/stats_tree.c (révision 20702) +++ epan/stats_tree.c (copie de travail) @@ -29,6 +29,7 @@ #include <glib.h> #include <epan/stats_tree_priv.h> +#include <epan/ws_strsplit.h> #include <string.h> #include "stats_tree.h" @@ -541,48 +542,42 @@ * */ static range_pair_t* get_range(guint8* rngstr) { - gchar** split; - range_pair_t* rng; - - split = g_strsplit((gchar*)rngstr,"-",2); + gchar** split; + range_pair_t* rng; - /* empty string */ - if (split[0] == NULL) { - g_strfreev(split); - return NULL; - } + split = g_strsplit((gchar*)rngstr,"-",2); -#if GLIB_MAJOR_VERSION >= 2 - /* means we have a non empty string - * which does not contain a delimiter */ - if (split[1] == NULL) { - g_strfreev(split); - return NULL; - } -#endif + /* empty string */ + if (split[0] == NULL) { + g_strfreev(split); + return NULL; + } - rng = g_malloc(sizeof(range_pair_t)); + /* means we have a non empty string + * which does not contain a delimiter */ + if (split[1] == NULL) { + g_strfreev(split); + return NULL; + } - /* string == "X-?" */ - if (*(split[0]) != '\0') { - rng->floor = strtol(split[0],NULL,10); - } else - /* string == "-?" */ - rng->floor = G_MININT; + rng = g_malloc(sizeof(range_pair_t)); - /* string != "?-" */ -#if GLIB_MAJOR_VERSION >= 2 - if (*(split[1]) != '\0') { -#else - if (split[1] != NULL) { -#endif - rng->ceil = strtol(split[1],NULL,10); - } else - /* string == "?-" */ - rng->ceil = G_MAXINT; - - g_strfreev(split); - + /* string == "X-?" */ + if (*(split[0]) != '\0') { + rng->floor = strtol(split[0],NULL,10); + } else + /* string == "-?" */ + rng->floor = G_MININT; + + /* string != "?-" */ + if (*(split[1]) != '\0') { + rng->ceil = strtol(split[1],NULL,10); + } else + /* string == "?-" */ + rng->ceil = G_MAXINT; + + g_strfreev(split); + return rng; } @@ -595,7 +590,7 @@ guint8* curr_range; stat_node* rng_root = new_stat_node(st, name, parent_id, FALSE, TRUE); stat_node* range_node = NULL; - + va_start( list, parent_id ); while (( curr_range = va_arg(list, guint8*) )) { range_node = new_stat_node(st, curr_range, rng_root->id, FALSE, FALSE); Index: epan/ex-opt.c =================================================================== --- epan/ex-opt.c (révision 20702) +++ epan/ex-opt.c (copie de travail) @@ -32,6 +32,7 @@ #include <glib.h> #include "ex-opt.h" +#include <epan/ws_strsplit.h> static GHashTable* ex_opts = NULL; Index: epan/crypt/airpdcap.c =================================================================== --- epan/crypt/airpdcap.c (révision 20702) +++ epan/crypt/airpdcap.c (copie de travail) @@ -35,6 +35,7 @@ #include <epan/tvbuff.h> #include <epan/crc32.h> #include <epan/strutil.h> +#include <epan/ws_strsplit.h> #include "airpdcap_system.h" #include "airpdcap_int.h" Index: epan/dissectors/packet-jxta.c =================================================================== --- epan/dissectors/packet-jxta.c (révision 20702) +++ epan/dissectors/packet-jxta.c (copie de travail) @@ -46,6 +46,7 @@ #include <epan/prefs.h> #include <epan/tap.h> #include <epan/emem.h> +#include <epan/ws_strsplit.h> #include "packet-jxta.h" Index: epan/dissectors/packet-http.c =================================================================== --- epan/dissectors/packet-http.c (révision 20702) +++ epan/dissectors/packet-http.c (copie de travail) @@ -44,6 +44,7 @@ #include <epan/base64.h> #include <epan/emem.h> #include <epan/stats_tree.h> +#include <epan/ws_strsplit.h> #include <epan/req_resp_hdrs.h> #include "packet-http.h" Index: epan/dissectors/packet-k12.c =================================================================== --- epan/dissectors/packet-k12.c (révision 20702) +++ epan/dissectors/packet-k12.c (copie de travail) @@ -37,6 +37,7 @@ #include <epan/report_err.h> #include <epan/emem.h> #include "packet-sscop.h" +#include <epan/ws_strsplit.h> static int proto_k12 = -1; Index: tap-funnel.c =================================================================== --- tap-funnel.c (révision 20702) +++ tap-funnel.c (copie de travail) @@ -30,6 +30,7 @@ #include <epan/funnel.h> #include <stdio.h> #include <epan/stat_cmd_args.h> +#include <epan/ws_strsplit.h> struct _funnel_text_window_t {
- Follow-Ups:
- Re: [Wireshark-dev] [PATCH] Fixup for a segfault with gtk1.2
- From: Stephen Fisher
- Re: [Wireshark-dev] [PATCH] Fixup for a segfault with gtk1.2
- From: Stephen Fisher
- Re: [Wireshark-dev] [PATCH] Fixup for a segfault with gtk1.2
- Prev by Date: Re: [Wireshark-dev] (no subject)
- Next by Date: Re: [Wireshark-dev] [PATCH] Read VPI/VCI/CID information from K12xx .rf5 with extra_len == 0
- Previous by thread: Re: [Wireshark-dev] (no subject)
- Next by thread: Re: [Wireshark-dev] [PATCH] Fixup for a segfault with gtk1.2
- Index(es):