Pekka Lampila
2007-Sep-02 21:50 UTC
[Swfdec] libswfdec/swfdec_as_array.c libswfdec/swfdec_as_string.c
libswfdec/swfdec_as_array.c | 5 +++++ libswfdec/swfdec_as_string.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) New commits: diff-tree 362b6d991a6595468790b564501fb4f3b94d3a41 (from aa5947ee972f285b59556ab8888081addd458bfe) Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Mon Sep 3 00:49:47 2007 +0300 Fix various String functions and Array sort crashing when called on other object diff --git a/libswfdec/swfdec_as_array.c b/libswfdec/swfdec_as_array.c index 273b083..ff446d8 100644 --- a/libswfdec/swfdec_as_array.c +++ b/libswfdec/swfdec_as_array.c @@ -943,6 +943,11 @@ swfdec_as_array_sort (SwfdecAsContext *c ForeachSortData fdata; guint pos; + if (!SWFDEC_IS_AS_ARRAY (object)) { + SWFDEC_FIXME ("Array.sort should work on non-array objects too"); + return; + } + fdata.length = swfdec_as_array_get_length (object); fdata.order_size MIN ((gint32)g_hash_table_size (object->properties) + 1, fdata.length + 1); diff --git a/libswfdec/swfdec_as_string.c b/libswfdec/swfdec_as_string.c index 5988369..cce29bf 100644 --- a/libswfdec/swfdec_as_string.c +++ b/libswfdec/swfdec_as_string.c @@ -99,6 +99,9 @@ swfdec_as_string_lastIndexOf (SwfdecAsCo gsize len; const char *s; + if (argc < 1) + return; + s = swfdec_as_value_to_string (object->context, &argv[0]); if (argc == 2) { int offset = swfdec_as_value_to_integer (object->context, &argv[1]); @@ -127,6 +130,9 @@ swfdec_as_string_indexOf (SwfdecAsContex int offset=0, len, i=-1; const char *s, *t = NULL; + if (argc < 1) + return; + s = swfdec_as_value_to_string (object->context, &argv[0]); if (argc == 2) offset = swfdec_as_value_to_integer (object->context, &argv[1]); @@ -152,6 +158,9 @@ swfdec_as_string_charAt (SwfdecAsContext int i; const char *s, *t; + if (argc < 1) + return; + i = swfdec_as_value_to_integer (object->context, &argv[0]); if (i < 0) { SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_EMPTY); @@ -177,6 +186,9 @@ swfdec_as_string_charCodeAt (SwfdecAsCon const char *s; gunichar c; + if (argc < 1) + return; + i = swfdec_as_value_to_integer (cx, &argv[0]); if (i < 0) { SWFDEC_AS_VALUE_SET_NUMBER (ret, NAN); @@ -289,9 +301,10 @@ void swfdec_as_string_toString (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret) { - SwfdecAsString *string = SWFDEC_AS_STRING (object); + if (!SWFDEC_IS_AS_STRING (object)) + return; - SWFDEC_AS_VALUE_SET_STRING (ret, string->string); + SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STRING (object)->string); } SWFDEC_AS_NATIVE (251, 1, swfdec_as_string_valueOf) @@ -299,9 +312,10 @@ void swfdec_as_string_valueOf (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret) { - SwfdecAsString *string = SWFDEC_AS_STRING (object); + if (!SWFDEC_IS_AS_STRING (object)) + return; - SWFDEC_AS_VALUE_SET_STRING (ret, string->string); + SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STRING (object)->string); } #if 0 @@ -322,6 +336,9 @@ swfdec_as_string_split_5 (SwfdecAsContex const char *str, *end, *delim; int count; + if (argc < 1) + return; + str = swfdec_as_string_object_to_string (cx, object); arr = SWFDEC_AS_ARRAY (swfdec_as_array_new (cx)); if (arr == NULL) @@ -376,6 +393,9 @@ swfdec_as_string_split_6 (SwfdecAsContex int count; guint len; + if (argc < 1) + return; + str = swfdec_as_string_object_to_string (cx, object); arr = SWFDEC_AS_ARRAY (swfdec_as_array_new (cx)); if (arr == NULL) @@ -453,6 +473,9 @@ swfdec_as_string_substr (SwfdecAsContext const char *string = swfdec_as_string_object_to_string (cx, object); int from, to, len; + if (argc < 1) + return; + from = swfdec_as_value_to_integer (cx, &argv[0]); len = g_utf8_strlen (string, -1); @@ -487,6 +510,9 @@ swfdec_as_string_substring (SwfdecAsCont const char *string = swfdec_as_string_object_to_string (cx, object); int from, to, len; + if (argc < 1) + return; + len = g_utf8_strlen (string, -1); from = swfdec_as_value_to_integer (cx, &argv[0]); if (argc > 1) {
Maybe Matching Threads
- 7 commits - libswfdec/swfdec_as_context.c libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_object.h libswfdec/swfdec_as_string.c test/trace
- Branch 'as' - 3 commits - libswfdec/swfdec_as_array.c libswfdec/swfdec_as_context.c libswfdec/swfdec_as_math.c libswfdec/swfdec_as_native_function.c libswfdec/swfdec_as_number.c libswfdec/swfdec_as_object.c libswfdec/swfdec_as_string.c
- 5 commits - doc/Makefile.am doc/swfdec-sections.txt libswfdec/swfdec_as_array.c libswfdec/swfdec_as_boolean.c libswfdec/swfdec_asbroadcaster.c libswfdec/swfdec_as_internal.h libswfdec/swfdec_as_native_function.c libswfdec/swfdec_as_native_function.h
- 2 commits - libswfdec/swfdec_as_array.c libswfdec/swfdec_asbroadcaster.c libswfdec/swfdec_as_object.c libswfdec/swfdec_as_string.c libswfdec/swfdec_color_as.c libswfdec/swfdec_initialize.as
- Branch 'as' - 3 commits - libswfdec/swfdec_as_string.c libswfdec/swfdec_as_strings.c test/trace