gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10534: Properly support hex and oct


From: Sandro Santilli
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10534: Properly support hex and oct input for string-to-number, fixing tests in ours and swfdec testsuite
Date: Fri, 09 Jan 2009 22:10:24 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10534
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Fri 2009-01-09 22:10:24 +0100
message:
  Properly support hex and oct input for string-to-number, fixing tests in ours 
and swfdec testsuite
modified:
  libcore/as_value.cpp
  testsuite/actionscript.all/Global.as
  testsuite/actionscript.all/Number.as
  testsuite/swfdec/PASSING
=== modified file 'libcore/as_value.cpp'
--- a/libcore/as_value.cpp      2009-01-09 13:50:44 +0000
+++ b/libcore/as_value.cpp      2009-01-09 21:10:24 +0000
@@ -649,17 +649,33 @@
         case STRING:
         {
             std::string s = getStr();
+            if ( s.empty() ) {
+                return static_cast<double>( swfversion >= 5 ? NaN : 0.0 );
+            }
 
             if ( swfversion > 5 )
             {
-                if ( s.length() == 8 && s[0] == '0' && ( s[1] == 'x' || s[1] 
== 'X' ) )
+                size_t slen = s.length();
+                if ( slen > 2 ) // "0#" would still be octal, but has the same 
value of the decimal equivalent
                 {
-                    try {
-                        boost::uint8_t r = (parseHex(s[2])<<4) + 
parseHex(s[3]);
-                        boost::uint8_t g = (parseHex(s[4])<<4) + 
parseHex(s[5]);
-                        boost::uint8_t b = (parseHex(s[6])<<4) + 
parseHex(s[7]);
-                        return (double)((r<<16)|(g<<8)|b);
-                    } catch (invalidHexDigit) { }
+                    if ( s[0] == '0' && (s[1] == 'x' || s[1] == 'X') )
+                    {
+                        // base 16
+                        const char* cs = s.c_str();
+                        char* end;
+                        boost::int32_t i = strtol (cs+2, &end, 16); // 
truncation to 32bit is intentional
+                        double d = (double)i;
+                        if ( *end == '\0' ) return d;
+                    }
+                    else if ( (s[0] == '0' || ((s[0] == '-' || s[0] == '+') && 
s[1] == '0'))
+                         && s.find_first_not_of("01234567", 1) == 
std::string::npos )
+                    {
+                            // base 8
+                            const char* cs = s.c_str();
+                            char* end;
+                            double d = (double)strtol (cs, &end, 8); // 
include sign
+                            if ( *end == '\0' ) return d;
+                    }
                 }
             }
             else if (swfversion <= 4)

=== modified file 'testsuite/actionscript.all/Global.as'
--- a/testsuite/actionscript.all/Global.as      2009-01-09 12:30:36 +0000
+++ b/testsuite/actionscript.all/Global.as      2009-01-09 21:10:24 +0000
@@ -429,8 +429,8 @@
 check_equals(int("0123"), 123);
 check_equals(int("-0123"), -123);
 #else
-xcheck_equals(int("0123"), 83);
-xcheck_equals(int("-0123"), -83);
+check_equals(int("0123"), 83);
+check_equals(int("-0123"), -83);
 #endif
 check_equals(int("   0123"), 123);
 check_equals(int("-   0123"), 0);
@@ -444,8 +444,8 @@
 check_equals(int("0x-10"), 0);
 check_equals(int("0X+10"), 0);
 #else
-xcheck_equals(int("0x-10"), -16);
-xcheck_equals(int("0X+10"), 16);
+check_equals(int("0x-10"), -16);
+check_equals(int("0X+10"), 16);
 #endif
 
 /// Extraneous characters

=== modified file 'testsuite/actionscript.all/Number.as'
--- a/testsuite/actionscript.all/Number.as      2009-01-09 12:55:01 +0000
+++ b/testsuite/actionscript.all/Number.as      2009-01-09 21:10:24 +0000
@@ -305,6 +305,8 @@
  check_equals("0XFF0000", 0xFF0000);
  check_equals("0Xff0000", 0xFF0000);
  check("0Xff000000" != 0xFF000000);
+ check_equals("07700000000", 07700000000);
+ check("077000000000" != 077000000000);
 #else
  check("0xFF0000" != 0xFF0000);
  check("0XFF0000" != 0xFF0000);
@@ -595,29 +597,53 @@
 #if OUTPUT_VERSION < 6
  check(isNaN(a));
 #else
- xcheck_equals(a, 2);
+ check_equals(a, 2);
 #endif
 
 a=Number("0x2"); 
 #if OUTPUT_VERSION < 6
  check(isNaN(a));
 #else
- xcheck_equals(a, 2);
+ check_equals(a, 2);
 #endif
 
 a=new Number(" 0x2");
 check(isNaN(a));
 
+a=Number("077");
+#if OUTPUT_VERSION < 6
+ check_equals(a, 77);
+#else
+ check_equals(a, 63);
+#endif
+
+a=Number("-077");
+#if OUTPUT_VERSION < 6
+ check_equals(a, -77);
+#else
+ check_equals(a, -63);
+#endif
+
+a=Number("+077");
+#if OUTPUT_VERSION < 6
+ check_equals(a, 77);
+#else
+ check_equals(a, 63);
+#endif
+
+a=Number(" 077");
+check_equals(a, 77);
+
 check( isNaN(0/0) );
 
 // END OF TEST
 
 #if OUTPUT_VERSION < 6
- check_totals(223);
+ check_totals(227);
 #else
 #if OUTPUT_VERSION < 7
- check_totals(216);
+ check_totals(222);
 #else
- check_totals(214);
+ check_totals(220);
 #endif
 #endif

=== modified file 'testsuite/swfdec/PASSING'
--- a/testsuite/swfdec/PASSING  2009-01-09 13:50:44 +0000
+++ b/testsuite/swfdec/PASSING  2009-01-09 21:10:24 +0000
@@ -712,7 +712,10 @@
 parse-float-7.swf:59f1473e30db1f375f8c4734984ce9d6
 parse-int-5.swf:7917fb0d0cbb74bc8a54535af11e004f
 parse-int-6.swf:1645c51fb581cdb57070c243fc08554d
+parse-int-6.swf:b46dfcf60a6f1e94123daac657994681
 parse-int-7.swf:884940ca734ece1247966de88e974d6c
+parse-int-7.swf:a2d06192e9f2388546cd066e41b140d3
+parse-int-8.swf:40e2b74c8487204c9d955e8c19bdfe71
 place-object-6.swf:8c57ef22be77524807f9f2bec40af09b
 place-object-7.swf:1254ea2e2f8177b6a70ad712c73226a4
 place-object-button-5.swf:6e58db549a9aeb4f0092646b71affdb3
@@ -1089,6 +1092,9 @@
 string-split-empty-7.swf:3be198e0f9277bf4749bddddf85dce33
 string-split-empty-8.swf:0fa43138d18306e83d7cccadd1e8c9e9
 string-to-number-5.swf:eda0a656d7daf433de63cdddb24019e8
+string-to-number-6.swf:35737c2ba0e8c518dd84c3ea6a29a9c3
+string-to-number-7.swf:071ca70d724a7e73da4f1085051a5ba3
+string-to-number-8.swf:a1b04f36557ef7f4fb0b57d4a37ffedb
 string-trace-5.swf:14759c53a46b39e873a3f928a3e992f5
 string-trace-6.swf:286e55256f525f4220a324a7417e4051
 string-trace-7.swf:f6eac71a2fc50323a5bd4a74eec99dca


reply via email to

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