aboutsummaryrefslogtreecommitdiffstats
path: root/epan/stats_tree.c
diff options
context:
space:
mode:
authorStephen Fisher <steve@stephen-fisher.com>2007-01-21 22:45:58 +0000
committerStephen Fisher <steve@stephen-fisher.com>2007-01-21 22:45:58 +0000
commitd39a4f7aa7a3e3e68061f04011115a7d1b565354 (patch)
tree7ea005bf2d4fc8ce2cbdd5751720ec643ba69d2a /epan/stats_tree.c
parent21b8d9cd900c498c97c1c42bc660e4311d0dc01b (diff)
From Sebastien Tandel:
patch against a crash of wireshark with gtk1.2 when using packet length statistics window. The crash was due to a difference of implementation of g_strsplit between gtk1.2 and gtk2. svn path=/trunk/; revision=20518
Diffstat (limited to 'epan/stats_tree.c')
-rw-r--r--epan/stats_tree.c59
1 files changed, 52 insertions, 7 deletions
diff --git a/epan/stats_tree.c b/epan/stats_tree.c
index e70cde665c..dd4e8f0161 100644
--- a/epan/stats_tree.c
+++ b/epan/stats_tree.c
@@ -524,18 +524,63 @@ extern guint8* stats_tree_get_abbr(const guint8* optarg) {
}
+/*
+ * This function accepts an input string which should define a long integer range.
+ * The normal result is a struct containing the floor and ceil value of this
+ * range.
+ *
+ * It is allowed to define a range string in the following ways :
+ *
+ * "0-10" -> { 0, 10 }
+ * "-0" -> { G_MININT, 0 }
+ * "0-" -> { 0, G_MAXINT }
+ * "-" -> { G_MININT, G_MAXINT }
+ *
+ * Note that this function is robust to buggy input string. If in some cases it
+ * returns NULL, it but may also return a pair with undefined values.
+ *
+ */
static range_pair_t* get_range(guint8* rngstr) {
gchar** split;
- range_pair_t* rng = g_malloc(sizeof(range_pair_t));
+ range_pair_t* rng;
- split = g_strsplit(rngstr,"-",2);
+ split = g_strsplit((gchar*)rngstr,"-",2);
- rng->floor = strtol(split[0],NULL,10);
- rng->ceil = strtol(split[1],NULL,10);
-
- if (rng->ceil == 0) rng->ceil = G_MAXINT;
- if (rng->floor == 0) rng->floor = G_MININT;
+ /* empty string */
+ if (split[0] == NULL) {
+ g_strfreev(split);
+ return NULL;
+ }
+#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
+
+ rng = g_malloc(sizeof(range_pair_t));
+
+ /* string == "X-?" */
+ if (*(split[0]) != '\0') {
+ rng->floor = strtol(split[0],NULL,10);
+ } else
+ /* string == "-?" */
+ rng->floor = G_MININT;
+
+ /* 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);
return rng;