summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@gnome.org>2004-03-07 17:24:52 +0000
committerDodji Seketeli <dodji@src.gnome.org>2004-03-07 17:24:52 +0000
commitac4bea1c6d6ec8f63a43a2547a82406b3670ac90 (patch)
treeb024fbcf29ef8e72907aeccad343f1062ffc07c7
parent94f1a410a3d257124c3131b41ccaa883ccabb9c3 (diff)
downloadlibcroco-ac4bea1c6d6ec8f63a43a2547a82406b3670ac90.tar.gz
fixed a memory management bug reported by Rob BUIS.INITIAL_GNU_ARCH_IMPORTGNOME_2_6_ANCHOR
2004-03-07 Dodji Seketeli <dodji@gnome.org> * src/cr-statement.c: (parse_page_start_page_cb) fixed a memory management bug reported by Rob BUIS. (cr_statement_at_page_rule_to_string): added this new helper function. (cr_statement_dump_page): make this use cr_statement_at_page_rule_to_string(). * tests/test4-main.c: (test_cr_statement_at_page_rule_parse_from_buf): added this to start debugging a problem related to @page rule parsing.
-rw-r--r--ChangeLog13
-rw-r--r--src/cr-statement.c105
-rw-r--r--tests/test4-main.c34
3 files changed, 96 insertions, 56 deletions
diff --git a/ChangeLog b/ChangeLog
index 4df1fef..1d80d96 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2004-03-07 Dodji Seketeli <dodji@gnome.org>
+ * src/cr-statement.c:
+ (parse_page_start_page_cb) fixed a memory management bug
+ reported by Rob BUIS.
+ (cr_statement_at_page_rule_to_string): added this new
+ helper function.
+ (cr_statement_dump_page): make this use
+ cr_statement_at_page_rule_to_string().
+ * tests/test4-main.c:
+ (test_cr_statement_at_page_rule_parse_from_buf): added this
+ to start debugging a problem related to @page rule parsing.
+
+2004-03-07 Dodji Seketeli <dodji@gnome.org>
+
* src/*.c: re-indented the source files to make'em comply
with gnome indentation rules.
* libcroco-indent: added this indentation script.
diff --git a/src/cr-statement.c b/src/cr-statement.c
index 87f2d60..bf25d71 100644
--- a/src/cr-statement.c
+++ b/src/cr-statement.c
@@ -155,9 +155,18 @@ parse_page_start_page_cb (CRDocHandler * a_this,
{
CRStatement *stmt = NULL;
enum CRStatus status = CR_OK;
-
- stmt = cr_statement_new_at_page_rule (NULL, NULL, a_name,
- a_pseudo_page);
+ GString *page_name = NULL, *pseudo_name = NULL ;
+
+ if (a_name)
+ page_name = g_string_new_len (a_name->str,
+ a_name->len) ;
+ if (a_pseudo_page)
+ pseudo_name = g_string_new_len (a_pseudo_page->str,
+ a_pseudo_page->len) ;
+ stmt = cr_statement_new_at_page_rule (NULL, NULL, page_name,
+ pseudo_name);
+ page_name = NULL ;
+ pseudo_name = NULL ;
g_return_if_fail (stmt);
status = cr_doc_handler_set_ctxt (a_this, stmt);
g_return_if_fail (status == CR_OK);
@@ -688,6 +697,55 @@ cr_statement_dump_charset (CRStatement * a_this, FILE * a_fp, gulong a_indent)
}
/**
+ *Serialises the at page rule statement into a string
+ *@param a_this the current instance of #CRStatement. Must
+ *be an "@page" rule statement.
+ *@return the serialized string. Must be freed by the caller
+ */
+static gchar *
+cr_statement_at_page_rule_to_string (CRStatement *a_this,
+ gulong a_indent)
+{
+ GString *stringue = NULL;
+ gchar *result = NULL ;
+
+ stringue = g_string_new (NULL) ;
+
+ cr_utils_dump_n_chars2 (' ', stringue, a_indent) ;
+ g_string_append_printf (stringue, "@page");
+
+ if (a_this->kind.page_rule->name) {
+ g_string_append_printf
+ (stringue, " %s",
+ a_this->kind.page_rule->name->str) ;
+ } else {
+ g_string_append_printf (stringue, " ");
+ }
+ if (a_this->kind.page_rule->pseudo) {
+ g_string_append_printf
+ (stringue, " :%s",
+ a_this->kind.page_rule->pseudo->str) ;
+ }
+ if (a_this->kind.page_rule->decl_list) {
+ gchar *str = NULL ;
+ g_string_append_printf (stringue, " {\n");
+ str = cr_declaration_list_to_string2
+ (a_this->kind.page_rule->decl_list,
+ a_indent + DECLARATION_INDENT_NB, TRUE) ;
+ if (str) {
+ g_string_append_printf (stringue, "%s", str) ;
+ g_free (str) ;
+ str = NULL ;
+ }
+ g_string_append_printf (stringue, "%s", "\n}\n");
+ }
+ result = stringue->str ;
+ g_string_free (stringue, FALSE) ;
+ stringue = NULL ;
+ return result ;
+}
+
+/**
*Dumps an @page rule statement on stdout.
*@param a_this the statement to dump on stdout.
*@param a_fp the destination file pointer.
@@ -702,42 +760,15 @@ cr_statement_dump_page (CRStatement * a_this, FILE * a_fp, gulong a_indent)
&& a_this->type == AT_PAGE_RULE_STMT
&& a_this->kind.page_rule);
- cr_utils_dump_n_chars (' ', a_fp, a_indent);
- fprintf (a_fp, "@page");
-
- if (a_this->kind.page_rule->name) {
- str = g_strndup (a_this->kind.page_rule->name->str,
- a_this->kind.page_rule->name->len);
- g_return_if_fail (str);
- fprintf (a_fp, " %s", str);
- if (str) {
- g_free (str);
- str = NULL;
- }
- } else {
- fprintf (a_fp, " ");
- }
-
- if (a_this->kind.page_rule->pseudo) {
- str = g_strndup (a_this->kind.page_rule->pseudo->str,
- a_this->kind.page_rule->pseudo->len);
- g_return_if_fail (str);
- fprintf (a_fp, " :%s", str);
- if (str) {
- g_free (str);
- str = NULL;
- }
- }
-
- if (a_this->kind.page_rule->decl_list) {
- fprintf (a_fp, " {\n");
- cr_declaration_dump
- (a_this->kind.page_rule->decl_list,
- a_fp, a_indent + DECLARATION_INDENT_NB, TRUE);
- fprintf (a_fp, "\n}\n");
+ str = cr_statement_at_page_rule_to_string (a_this, a_indent) ;
+ if (str) {
+ fprintf (a_fp, str);
+ g_free (str) ;
+ str = NULL ;
}
}
+
/**
*Return the number of rules in the statement list;
*@param a_this the current instance of #CRStatement.
@@ -1384,7 +1415,7 @@ cr_statement_new_at_page_rule (CRStyleSheet * a_sheet,
cr_declaration_ref (a_decl_list);
}
result->kind.page_rule->name = a_name;
- result->kind.page_rule->name = a_pseudo;
+ result->kind.page_rule->pseudo = a_pseudo;
if (a_sheet)
cr_statement_set_parent_sheet (result, a_sheet);
diff --git a/tests/test4-main.c b/tests/test4-main.c
index ea51d68..5880cc5 100644
--- a/tests/test4-main.c
+++ b/tests/test4-main.c
@@ -133,6 +133,20 @@ test_cr_parser_parse (guchar * a_file_uri)
}
static enum CRStatus
+test_cr_statement_at_page_rule_parse_from_buf (void)
+{
+ CRStatement *stmt = NULL ;
+
+ stmt = cr_statement_at_page_rule_parse_from_buf
+ (gv_at_page_buf, CR_UTF_8) ;
+ if (!stmt) {
+ return CR_ERROR ;
+
+ }
+ return CR_OK ;
+}
+
+static enum CRStatus
test_cr_term_parse_expression_from_buf (void)
{
guchar *tmp_str = NULL;
@@ -244,23 +258,6 @@ test_cr_statement_at_media_rule_parse (void)
return CR_OK;
}
-static enum CRStatus
-test_cr_statement_at_page_rule_parse (void)
-{
- CRStatement *stmt = NULL;
-
- stmt = cr_statement_at_page_rule_parse_from_buf (gv_at_page_buf,
- CR_UTF_8);
-
- g_return_val_if_fail (stmt, CR_ERROR);
-
- if (stmt) {
- cr_statement_destroy (stmt);
- stmt = NULL;
- }
-
- return CR_OK;
-}
static enum CRStatus
test_cr_statement_at_charset_rule_parse (void)
@@ -392,8 +389,7 @@ main (int argc, char **argv)
if (status != CR_OK) {
g_print ("\ntest cr_statement_at_media_rule_parse() failed\n");
}
-
- test_cr_statement_at_page_rule_parse ();
+ test_cr_statement_at_page_rule_parse_from_buf ();
if (status != CR_OK) {
g_print ("\ntest cr_statement_at_page_rule_parse() failed\n");
return 0;