[Swfdec] 5 commits - libswfdec/swfdec_text_field.c libswfdec/swfdec_text_field_movie_as.c libswfdec/swfdec_text_field_movie.c libswfdec/swfdec_xml.c libswfdec/swfdec_xml_node.c

Pekka Lampila medar at kemper.freedesktop.org
Fri Nov 2 03:13:39 PDT 2007


 libswfdec/swfdec_text_field.c          |    2 +-
 libswfdec/swfdec_text_field_movie.c    |    9 ++-------
 libswfdec/swfdec_text_field_movie_as.c |   29 +++++++++++++++++++++--------
 libswfdec/swfdec_xml.c                 |   16 ++++++++++++++++
 libswfdec/swfdec_xml_node.c            |   17 ++++++++++++++---
 5 files changed, 54 insertions(+), 19 deletions(-)

New commits:
commit f293404b91a5c89e8fc84623817e70682dfbc487
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Nov 2 12:09:01 2007 +0200

    Bunch OOM fixes to XML code

diff --git a/libswfdec/swfdec_xml.c b/libswfdec/swfdec_xml.c
index 37174bc..b64b16e 100644
--- a/libswfdec/swfdec_xml.c
+++ b/libswfdec/swfdec_xml.c
@@ -563,6 +563,8 @@ swfdec_xml_parse_tag (SwfdecXml *xml, SwfdecXmlNode **node, const char *p)
     child = swfdec_xml_node_new_no_properties (
 	SWFDEC_AS_OBJECT (*node)->context, SWFDEC_XML_NODE_ELEMENT, name);
     g_free (name);
+    if (child == NULL)
+      return strchr (p, '\0');
   }
 
   if (close) {
@@ -643,6 +645,8 @@ swfdec_xml_parse_text (SwfdecXml *xml, SwfdecXmlNode *node,
     child = swfdec_xml_node_new_no_properties (
 	SWFDEC_AS_OBJECT (node)->context, SWFDEC_XML_NODE_TEXT, unescaped);
     g_free (unescaped);
+    if (child == NULL)
+      return strchr (p, '\0');
     swfdec_xml_node_appendChild (node, child);
   }
 
@@ -700,6 +704,9 @@ swfdec_xml_do_parseXML (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
   if (!SWFDEC_IS_XML (object))
     return;
 
+  if (!SWFDEC_IS_VALID_XML_NODE (object))
+    return;
+
   if (argc < 1)
     return;
 
@@ -729,6 +736,9 @@ swfdec_xml_createElement (SwfdecAsContext *cx, SwfdecAsObject *object,
 
   node = swfdec_xml_node_new (cx, SWFDEC_XML_NODE_ELEMENT,
       swfdec_as_value_to_string (cx, &argv[0]));
+  if (node == NULL)
+    return;
+
   SWFDEC_AS_VALUE_SET_OBJECT (rval, SWFDEC_AS_OBJECT (node));
 }
 
@@ -751,6 +761,9 @@ swfdec_xml_createTextNode (SwfdecAsContext *cx, SwfdecAsObject *object,
 
   node = swfdec_xml_node_new (cx, SWFDEC_XML_NODE_TEXT,
       swfdec_as_value_to_string (cx, &argv[0]));
+  if (node == NULL)
+    return;
+
   SWFDEC_AS_VALUE_SET_OBJECT (rval, SWFDEC_AS_OBJECT (node));
 }
 
@@ -813,6 +826,9 @@ swfdec_xml_construct (SwfdecAsContext *cx, SwfdecAsObject *object,
 
   SWFDEC_XML_NODE (object)->name = NULL;
 
+  if (!SWFDEC_IS_VALID_XML_NODE (object))
+    return;
+
   if (argc >= 1 && !SWFDEC_AS_VALUE_IS_UNDEFINED (&argv[0])) {
     swfdec_xml_parseXML (SWFDEC_XML (object),
 	swfdec_as_value_to_string (cx, &argv[0]));
diff --git a/libswfdec/swfdec_xml_node.c b/libswfdec/swfdec_xml_node.c
index a9ef3d0..71b7a5c 100644
--- a/libswfdec/swfdec_xml_node.c
+++ b/libswfdec/swfdec_xml_node.c
@@ -617,6 +617,8 @@ swfdec_xml_node_clone (SwfdecAsContext *cx, SwfdecXmlNode *node, gboolean deep)
   g_assert (SWFDEC_IS_VALID_XML_NODE (node));
 
   new = swfdec_xml_node_new (cx, SWFDEC_XML_NODE_ELEMENT, SWFDEC_AS_STR_EMPTY);
+  if (new == NULL)
+    return NULL;
 
   new->valid = TRUE;
   new->type = node->type;
@@ -635,6 +637,8 @@ swfdec_xml_node_clone (SwfdecAsContext *cx, SwfdecXmlNode *node, gboolean deep)
     for (i = 0; i < num; i++) {
       child = swfdec_xml_node_get_child (node, i);
       child_new = swfdec_xml_node_clone (cx, child, TRUE);
+      if (child_new == NULL)
+	return NULL;
       child_new->parent = new;
       SWFDEC_AS_VALUE_SET_OBJECT (&val, SWFDEC_AS_OBJECT (child_new));
       swfdec_as_array_push (new->children, &val);
@@ -664,6 +668,9 @@ swfdec_xml_node_cloneNode (SwfdecAsContext *cx, SwfdecAsObject *object,
   }
 
   new = swfdec_xml_node_clone (cx, SWFDEC_XML_NODE (object), deep);
+  if (new == NULL)
+    return;
+
   SWFDEC_AS_VALUE_SET_OBJECT (ret, SWFDEC_AS_OBJECT (new));
 }
 
@@ -968,6 +975,9 @@ swfdec_xml_node_init_values (SwfdecXmlNode *node, int type, const char* value)
   }
 
   node->childNodes = SWFDEC_AS_ARRAY (swfdec_as_array_new (object->context));
+
+  if (node->children == NULL || node->attributes == NULL || node->childNodes)
+    node->valid = FALSE;
 }
 
 static void
commit 3bb580e81b042e0a8a8267061f9991bdbcdf0fb6
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Nov 2 11:56:41 2007 +0200

    Create new object in swfdec_xml_node_new even if _global.XMLNode is missing

diff --git a/libswfdec/swfdec_xml_node.c b/libswfdec/swfdec_xml_node.c
index 457cd6b..a9ef3d0 100644
--- a/libswfdec/swfdec_xml_node.c
+++ b/libswfdec/swfdec_xml_node.c
@@ -1037,9 +1037,10 @@ swfdec_xml_node_new_no_properties (SwfdecAsContext *context,
   node = g_object_new (SWFDEC_TYPE_XML_NODE, NULL);
   swfdec_as_object_add (SWFDEC_AS_OBJECT (node), context, size);
   swfdec_as_object_get_variable (context->global, SWFDEC_AS_STR_XMLNode, &val);
-  if (!SWFDEC_AS_VALUE_IS_OBJECT (&val))
-    return NULL;
-  swfdec_as_object_set_constructor (SWFDEC_AS_OBJECT (node), SWFDEC_AS_VALUE_GET_OBJECT (&val));
+  if (SWFDEC_AS_VALUE_IS_OBJECT (&val)) {
+    swfdec_as_object_set_constructor (SWFDEC_AS_OBJECT (node),
+	SWFDEC_AS_VALUE_GET_OBJECT (&val));
+  }
 
   swfdec_xml_node_init_values (node, type,
       swfdec_as_context_get_string (SWFDEC_AS_OBJECT (node)->context, value));
commit fb38f6f974a113827e212b4de1d107b0ab46e85b
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Nov 2 11:49:59 2007 +0200

    One more change to make TextField independent of SwfdecColor implementation

diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index 70ce222..0b73b2b 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -486,7 +486,10 @@ swfdec_text_field_movie_get_backgroundColor (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
 
-  SWFDEC_AS_VALUE_SET_NUMBER (ret, text->background_color);
+  SWFDEC_AS_VALUE_SET_NUMBER (ret,
+      SWFDEC_COLOR_R (text->background_color) << 16 |
+      SWFDEC_COLOR_G (text->background_color) << 8 |
+      SWFDEC_COLOR_B (text->background_color));
 }
 
 static void
@@ -546,7 +549,11 @@ swfdec_text_field_movie_get_borderColor (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
 
-  SWFDEC_AS_VALUE_SET_NUMBER (ret, text->border_color & 0xffffff);
+
+  SWFDEC_AS_VALUE_SET_NUMBER (ret,
+      SWFDEC_COLOR_R (text->border_color) << 16 |
+      SWFDEC_COLOR_G (text->border_color) << 8 |
+      SWFDEC_COLOR_B (text->border_color));
 }
 
 static void
commit 625d6ff01fdd5cea2179ad51c6c4331d4741e152
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Nov 2 11:45:43 2007 +0200

    Clean up color handling in TextField

diff --git a/libswfdec/swfdec_text_field.c b/libswfdec/swfdec_text_field.c
index 77fa7ff..2a1436d 100644
--- a/libswfdec/swfdec_text_field.c
+++ b/libswfdec/swfdec_text_field.c
@@ -151,7 +151,7 @@ tag_func_define_edit_text (SwfdecSwfDecoder * s, guint tag)
     SWFDEC_LOG ("  color = %u", text->color);
   } else {
     SWFDEC_WARNING ("FIXME: figure out default color");
-    text->color = SWFDEC_COLOR_COMBINE (255, 255, 255, 255);
+    text->color = SWFDEC_COLOR_COMBINE (255, 255, 255, 0);
   }
 
   if (has_max_length) {
diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index a09610e..2ca9424 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -953,8 +953,8 @@ swfdec_text_field_movie_init_movie (SwfdecMovie *movie)
   text->format_new->indent = text->text->indent / 20;
   text->format_new->leading = text->text->leading / 20;
 
-  text->border_color = SWFDEC_COLOR_COMBINE (0, 0, 0, 255);
-  text->background_color = SWFDEC_COLOR_COMBINE (255, 255, 255, 255);
+  text->border_color = SWFDEC_COLOR_COMBINE (0, 0, 0, 0);
+  text->background_color = SWFDEC_COLOR_COMBINE (255, 255, 255, 0);
 
   // text
   if (text->text->input != NULL) {
diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index b7d7d18..70ce222 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -41,10 +41,13 @@ static SwfdecColor
 swfdec_text_field_movie_int_to_color (SwfdecAsContext *cx, int value)
 {
   if (value < 0) {
-    return 16777216 + value % 16777216;
+    value = (0xffffff + 1) + value % (0xffffff + 1);
   } else {
-    return value % 16777216;
+    value = value % (0xffffff + 1);
   }
+
+  return SWFDEC_COLOR_COMBINE (value >> 16 & 0xff, value >> 8 & 0xff,
+      value & 0xff, 0);
 }
 
 // does nothing but calls valueOf
@@ -483,7 +486,7 @@ swfdec_text_field_movie_get_backgroundColor (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "");
 
-  SWFDEC_AS_VALUE_SET_NUMBER (ret, text->background_color & 0xffffff);
+  SWFDEC_AS_VALUE_SET_NUMBER (ret, text->background_color);
 }
 
 static void
@@ -497,8 +500,7 @@ swfdec_text_field_movie_set_backgroundColor (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
 
-  color = (swfdec_text_field_movie_int_to_color (cx, value) & 0xffffff) +
-    (255 << 24);
+  color = swfdec_text_field_movie_int_to_color (cx, value);
   if (text->background_color != color) {
     text->background_color = color;
     swfdec_movie_invalidate (SWFDEC_MOVIE (text));
@@ -558,8 +560,7 @@ swfdec_text_field_movie_set_borderColor (SwfdecAsContext *cx,
 
   SWFDEC_AS_CHECK (SWFDEC_TYPE_TEXT_FIELD_MOVIE, &text, "i", &value);
 
-  color = (swfdec_text_field_movie_int_to_color (cx, value) & 0xffffff) +
-    (255 << 24);
+  color = swfdec_text_field_movie_int_to_color (cx, value);
   if (text->border_color != color) {
     text->border_color = color;
     swfdec_movie_invalidate (SWFDEC_MOVIE (text));
commit 6417627b2f42b9a8f61778472230247bbbf0854f
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date:   Fri Nov 2 11:18:33 2007 +0200

    Don't invalidate etc. inside set_text_format, leave as a job for the caller
    
    We want to update only once after parsing HTML

diff --git a/libswfdec/swfdec_text_field_movie.c b/libswfdec/swfdec_text_field_movie.c
index e127971..a09610e 100644
--- a/libswfdec/swfdec_text_field_movie.c
+++ b/libswfdec/swfdec_text_field_movie.c
@@ -1110,11 +1110,6 @@ swfdec_text_field_movie_set_text_format (SwfdecTextFieldMovie *text,
       findex = findex_prev;
     }
   }
-
-  swfdec_movie_invalidate (SWFDEC_MOVIE (text));
-  swfdec_text_field_movie_auto_size (text);
-  // special case: update the max values, not the current values
-  swfdec_text_field_movie_update_scroll (text, FALSE);
 }
 
 SwfdecTextFormat *
diff --git a/libswfdec/swfdec_text_field_movie_as.c b/libswfdec/swfdec_text_field_movie_as.c
index 673600e..b7d7d18 100644
--- a/libswfdec/swfdec_text_field_movie_as.c
+++ b/libswfdec/swfdec_text_field_movie_as.c
@@ -1036,6 +1036,11 @@ swfdec_text_field_movie_setTextFormat (SwfdecAsContext *cx,
       text->input->str,
       g_utf8_offset_to_pointer (text->input->str, end_index) -
       text->input->str);
+
+  swfdec_movie_invalidate (SWFDEC_MOVIE (text));
+  swfdec_text_field_movie_auto_size (text);
+  // special case: update the max values, not the current values
+  swfdec_text_field_movie_update_scroll (text, FALSE);
 }
 
 SWFDEC_AS_NATIVE (104, 101, swfdec_text_field_movie_getTextFormat)


More information about the Swfdec mailing list