diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-08-06 15:34:51 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-08-06 15:34:51 +0200 |
commit | 68e1ac4617108bb99b848bb1ccb1b55451f5b91b (patch) | |
tree | 63531ab6b75adb4421a11530b8254adedfd61acf | |
parent | 528e7edd28e36ed314e15975b8524a9020eaa065 (diff) | |
download | experiment-player-68e1ac4617108bb99b848bb1ccb1b55451f5b91b.tar.gz |
resolved pattern-length restriction bug by calculating the pattern+captures size
* also made gtk_experiment_transcript_free_formats() an internal function
* declare static functions in gtk-experiment-transcript-formats.c
-rw-r--r-- | lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c | 28 | ||||
-rw-r--r-- | lib/gtk-experiment-widgets/gtk-experiment-transcript-private.h | 1 |
2 files changed, 25 insertions, 4 deletions
diff --git a/lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c b/lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c index 7b3b0f7..c3dcbf8 100644 --- a/lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c +++ b/lib/gtk-experiment-widgets/gtk-experiment-transcript-formats.c @@ -39,9 +39,28 @@ #include "gtk-experiment-transcript.h" #include "gtk-experiment-transcript-private.h" +static inline gint attr_list_get_length(PangoAttrList *list); +static gboolean gtk_experiment_transcript_parse_format(GtkExperimentTranscriptFormat *fmt, + const gchar *str, + GError **error); + #define FORMAT_REGEX_COMPILE_FLAGS (G_REGEX_CASELESS) #define FORMAT_REGEX_MATCH_FLAGS (0) +static inline gint +attr_list_get_length(PangoAttrList *list) +{ + PangoAttrIterator *iter = pango_attr_list_get_iterator(list); + gint length = 0; + + do + length++; + while (pango_attr_iterator_next(iter)); + pango_attr_iterator_destroy(iter); + + return length; +} + static gboolean gtk_experiment_transcript_parse_format(GtkExperimentTranscriptFormat *fmt, const gchar *str, @@ -49,8 +68,7 @@ gtk_experiment_transcript_parse_format(GtkExperimentTranscriptFormat *fmt, { PangoAttrIterator *iter; - /** @bug will crash for long patterns */ - gchar *pattern, pattern_captures[255], *p; + gchar *pattern, *pattern_captures, *p; gint capture_count = 0; g_return_val_if_fail(error == NULL || *error == NULL, FALSE); @@ -59,7 +77,8 @@ gtk_experiment_transcript_parse_format(GtkExperimentTranscriptFormat *fmt, NULL, error)) return FALSE; - p = pattern_captures; + p = pattern_captures = g_malloc(strlen(pattern) + 1 + + 2*attr_list_get_length(fmt->attribs)); iter = pango_attr_list_get_iterator(fmt->attribs); do { gint start, end; @@ -83,6 +102,7 @@ gtk_experiment_transcript_parse_format(GtkExperimentTranscriptFormat *fmt, fmt->regexp = g_regex_new(pattern_captures, FORMAT_REGEX_COMPILE_FLAGS, 0, error); + g_free(pattern_captures); if (fmt->regexp == NULL) { gtk_experiment_transcript_free_format(fmt); fmt->attribs = NULL; @@ -161,7 +181,7 @@ gtk_experiment_transcript_apply_format(GtkExperimentTranscriptFormat *fmt, } /** @private */ -void +G_GNUC_INTERNAL void gtk_experiment_transcript_free_formats(GSList *formats) { for (GSList *cur = formats; cur != NULL; cur = cur->next) { diff --git a/lib/gtk-experiment-widgets/gtk-experiment-transcript-private.h b/lib/gtk-experiment-widgets/gtk-experiment-transcript-private.h index 82eb94e..42cbc98 100644 --- a/lib/gtk-experiment-widgets/gtk-experiment-transcript-private.h +++ b/lib/gtk-experiment-widgets/gtk-experiment-transcript-private.h @@ -127,6 +127,7 @@ gtk_experiment_transcript_free_format(GtkExperimentTranscriptFormat *format) } /** @private */ +G_GNUC_INTERNAL void gtk_experiment_transcript_free_formats(GSList *formats); #endif |