gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/swf/ASHandlers.cpp [release_0_7_2]


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/swf/ASHandlers.cpp [release_0_7_2]
Date: Sun, 05 Nov 2006 11:28:03 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Branch:         release_0_7_2
Changes by:     Sandro Santilli <strk>  06/11/05 11:28:03

Modified files:
        .              : ChangeLog 
        server/swf     : ASHandlers.cpp 

Log message:
                * server/swf/ASHandlers.cpp (ActionSubstring): early
                  return if input string is undefined or null; attempt
                  to support negative base args (untested: ming unable
                  to output such opcode). See bug #18204.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&only_with_tag=release_0_7_2&r1=1.1412.2.81&r2=1.1412.2.82
http://cvs.savannah.gnu.org/viewcvs/gnash/server/swf/ASHandlers.cpp?cvsroot=gnash&only_with_tag=release_0_7_2&r1=1.84.2.1&r2=1.84.2.2

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1412.2.81
retrieving revision 1.1412.2.82
diff -u -b -r1.1412.2.81 -r1.1412.2.82
--- ChangeLog   5 Nov 2006 11:16:20 -0000       1.1412.2.81
+++ ChangeLog   5 Nov 2006 11:28:03 -0000       1.1412.2.82
@@ -1,3 +1,10 @@
+2006-11-05 Sandro Santilli <address@hidden>
+
+       * server/swf/ASHandlers.cpp (ActionSubstring): early
+         return if input string is undefined or null; attempt
+         to support negative base args (untested: ming unable
+         to output such opcode). See bug #18204.
+
 2006-11-05 Markus Gothe <address@hidden>
 
        * macros/mad.m4: Fixed bogus test-case...

Index: server/swf/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/swf/ASHandlers.cpp,v
retrieving revision 1.84.2.1
retrieving revision 1.84.2.2
diff -u -b -r1.84.2.1 -r1.84.2.2
--- server/swf/ASHandlers.cpp   30 Oct 2006 14:28:55 -0000      1.84.2.1
+++ server/swf/ASHandlers.cpp   5 Nov 2006 11:28:03 -0000       1.84.2.2
@@ -16,7 +16,7 @@
 
 //
 
-/* $Id: ASHandlers.cpp,v 1.84.2.1 2006/10/30 14:28:55 rsavoye Exp $ */
+/* $Id: ASHandlers.cpp,v 1.84.2.2 2006/11/05 11:28:03 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -887,10 +887,39 @@
 //    GNASH_REPORT_FUNCTION;
     as_environment& env = thread.env;
     ensure_stack(env, 3); // size, base, string
-    int        size = int(env.top(0).to_number());
-    int        base = int(env.top(1).to_number()) - 1;  // 1-based indices
+
+    as_value& size_val = env.top(0);
+    as_value& base_val = env.top(1);
+    as_value& string_val = env.top(2);
+
+    // input checks
+    if ( string_val.is_undefined() || string_val.is_null() )
+    {
+       log_warning("Undefined or null string passed to ActionSubString, "
+               "returning undefined");
+       env.drop(2);
+       env.top(0).set_undefined();
+       return;
+    }
+
+    int        size = int(size_val.to_number());
+    int        base = int(base_val.to_number());  
     int version = env.get_version();
-    const tu_string&   str = env.top(2).to_tu_string_versioned(version);
+    const tu_string& str = string_val.to_tu_string_versioned(version);
+
+    // negative base refer to index from end
+    // -1 is *last* character, otherwise
+    // they are 1-based index from start
+    if ( base < 0 ) base += str.length();
+    else base = base-1;
+
+    // TODO: if 'base' or 'size' do not evaluate to numbers return 
+    //       the empty string (how do we check if they evaluate ??)
+
+    assert(base >= 0);
+
+
+    //log_msg("string: %s, size: %d, base: %d", str.c_str(), size, base);
     
     // Keep base within range.
     base = iclamp(base, 0, str.length());
@@ -898,8 +927,7 @@
     // Truncate if necessary.
     size = imin(str.length() - base, size);
     
-    // @@ This can be done without new allocations if we get dirtier w/ 
internals
-    // of as_value and tu_string...
+    // TODO: unsafe: use std::string::substr instead !
     tu_string  new_string = str.c_str() + base;
     new_string.resize(size);
     




reply via email to

[Prev in Thread] Current Thread [Next in Thread]