[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/asobj/Date.cpp server/as...
From: |
Martin Guy |
Subject: |
[Gnash-commit] gnash ChangeLog server/asobj/Date.cpp server/as... |
Date: |
Thu, 01 Feb 2007 23:18:21 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Martin Guy <martinwguy> 07/02/01 23:18:21
Modified files:
. : ChangeLog
server/asobj : Date.cpp Global.cpp string.cpp
Log message:
Convert all assert()s that triggered by illegal number of args in
runtime
ActionScript to IF_VERBOSE_ASCODING_ERRORS() warnings with and keep
going,
giving safe default return values.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2223&r2=1.2224
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Date.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Global.cpp?cvsroot=gnash&r1=1.38&r2=1.39
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/string.cpp?cvsroot=gnash&r1=1.13&r2=1.14
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2223
retrieving revision 1.2224
diff -u -b -r1.2223 -r1.2224
--- ChangeLog 1 Feb 2007 21:56:00 -0000 1.2223
+++ ChangeLog 1 Feb 2007 23:18:21 -0000 1.2224
@@ -1,3 +1,10 @@
+2007-02-01 Martin Guy <address@hidden>
+
+ * server/asobj/{Date,Global,string}.cpp: Convert all assert()s that
+ triggered by illegal number of args in runtime ActionScript
+ to IF_VERBOSE_ASCODING_ERRORS() warnings with and keep going,
+ giving safe default return values.
+
2007-02-01 Bastiaan Jacques <address@hidden>
* server/asobj/NetStreamFfmpeg.h: Switch multithread_queue over to
Index: server/asobj/Date.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Date.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- server/asobj/Date.cpp 23 Jan 2007 17:17:14 -0000 1.7
+++ server/asobj/Date.cpp 1 Feb 2007 23:18:21 -0000 1.8
@@ -486,29 +486,62 @@
// TODO: Also, confirm this is the appropriate behavior for the setUTC()
// functions. Right now, we convert the time to UTC, set the variable,
// then convert back to local time. We should confirm the official behavior!
+
void date_setdate(const fn_call& fn) {
- assert(fn.nargs == 1);
date_as_object* date = ensure_date_object(fn.this_ptr);
- date->obj.date = (long int)(fn.arg(0).to_number());
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
+ date->obj.date = (long int)(fn.arg(0).to_number());
date->obj.Normalize();
+ }
+
+ if (fn.nargs > 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than one argument");
+ )
+ }
+
fn.result->set_double(date->obj.getTime());
}
+
+/// \brief Set year [, month [, date]]
+
void date_setfullyear(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 3);
date_as_object* date = ensure_date_object(fn.this_ptr);
+
+ // assert(fn.nargs >= 1 && fn.nargs <= 3);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
date->obj.year = (long int)(fn.arg(0).to_number() - 1900);
if (fn.nargs >= 2)
date->obj.month = (long int)(fn.arg(1).to_number());
if (fn.nargs >= 3)
date->obj.date = (long int)(fn.arg(2).to_number());
-
+ if (fn.nargs > 3) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than three arguments");
+ )
+ }
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
void date_sethours(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 4);
date_as_object* date = ensure_date_object(fn.this_ptr);
+
+ // assert(fn.nargs >= 1 && fn.nargs <= 4);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
date->obj.hour = (long int)(fn.arg(0).to_number());
if (fn.nargs >= 2)
date->obj.minute = (long int)(fn.arg(1).to_number());
@@ -516,58 +549,124 @@
date->obj.second = (long int)(fn.arg(2).to_number());
if (fn.nargs >= 4)
date->obj.millisecond = (long int)(fn.arg(3).to_number());
-
+ if (fn.nargs > 4) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than four arguments");
+ )
+ }
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
void date_setmilliseconds(const fn_call& fn) {
- assert(fn.nargs == 1);
date_as_object* date = ensure_date_object(fn.this_ptr);
- date->obj.millisecond = (long int)(fn.arg(0).to_number());
+ // assert(fn.nargs == 1);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
+ date->obj.millisecond = (long int)(fn.arg(0).to_number());
+ if (fn.nargs > 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than one argument");
+ )
+ }
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
void date_setminutes(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 3);
date_as_object* date = ensure_date_object(fn.this_ptr);
+
+ //assert(fn.nargs >= 1 && fn.nargs <= 3);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
// Seconds (value between 0 and 59) won't be affected by timezone
date->obj.minute = (long int)(fn.arg(0).to_number());
if (fn.nargs >= 2) date->obj.second = (long int)(fn.arg(1).to_number());
if (fn.nargs >= 3) date->obj.millisecond = (long
int)(fn.arg(2).to_number());
-
+ if (fn.nargs > 3) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than three arguments");
+ )
+ }
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
void date_setmonth(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 2);
date_as_object* date = ensure_date_object(fn.this_ptr);
+
+ // assert(fn.nargs >= 1 && fn.nargs <= 2);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
date->obj.month = (long int)(fn.arg(0).to_number());
if (fn.nargs >= 2)
date->obj.date = (long int)(fn.arg(1).to_number());
+ if (fn.nargs > 2) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than two arguments");
+ )
+ }
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
void date_setseconds(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 2);
date_as_object* date = ensure_date_object(fn.this_ptr);
+
+ // assert(fn.nargs >= 1 && fn.nargs <= 2);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
// Seconds (value between 0 and 59) won't be affected by timezone
date->obj.second = (long int)(fn.arg(0).to_number());
- if (fn.nargs >= 2) date->obj.millisecond = (long
int)(fn.arg(1).to_number());
+ if (fn.nargs >= 2)
+ date->obj.millisecond = (long int)(fn.arg(1).to_number());
+ if (fn.nargs > 2) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than two arguments");
+ )
+ }
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
void date_settime(const fn_call& fn) {
date_as_object* date = ensure_date_object(fn.this_ptr);
- UNUSED(date);
+
+ // assert(fn.nargs == 1);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
log_msg("%s:unimplemented \n", __FUNCTION__);
+ }
+
+ fn.result->set_double(date->obj.getTime());
}
void date_setutcdate(const fn_call& fn) {
- assert(fn.nargs == 1);
date_as_object* date = ensure_date_object(fn.this_ptr);
+ // assert(fn.nargs == 1);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
tm utctime = date->obj.convertUTC();
// Set mday to our new UTC date (yday and wday don't need to be set)
utctime.tm_mday = int(fn.arg(0).to_number());
@@ -579,12 +678,24 @@
time_t newtime = mktime(&utctime);
date->obj.setFromTM(*(localtime(&newtime)));
+ if (fn.nargs > 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than one argument");
+ )
+ }
+ }
+
fn.result->set_double(date->obj.getTime());
}
void date_setutcfullyear(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 3);
date_as_object* date = ensure_date_object(fn.this_ptr);
+ // assert(fn.nargs >= 1 && fn.nargs <= 3);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
tm utctime = date->obj.convertUTC();
// Set year to our new UTC date
utctime.tm_year = int(fn.arg(0).to_number()-1900);
@@ -592,6 +703,11 @@
utctime.tm_mon = (long int)(fn.arg(1).to_number());
if (fn.nargs >= 3)
utctime.tm_mday = (long int)(fn.arg(2).to_number());
+ if (fn.nargs > 3) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than three arguments");
+ )
+ }
// Convert back from UTC to local time
utctime.tm_min += date->obj.minutesEast;
@@ -599,13 +715,20 @@
// Normalize the time, then set as this object's new time
time_t newtime = mktime(&utctime);
date->obj.setFromTM(*(localtime(&newtime)));
+ }
fn.result->set_double(date->obj.getTime());
}
void date_setutchours(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 4);
date_as_object* date = ensure_date_object(fn.this_ptr);
+ // assert(fn.nargs >= 1 && fn.nargs <= 4);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
+
if (fn.nargs >= 4)
{
date->obj.millisecond = (long int)(fn.arg(3).to_number());
@@ -619,6 +742,11 @@
utctime.tm_min = (long int)(fn.arg(1).to_number());
if (fn.nargs >= 3)
utctime.tm_sec = (long int)(fn.arg(2).to_number());
+ if (fn.nargs > 4) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than four arguments");
+ )
+ }
// Convert back from UTC to local time
utctime.tm_min += date->obj.minutesEast;
@@ -626,41 +754,78 @@
// Normalize the time, then set as this object's new time
time_t newtime = mktime(&utctime);
date->obj.setFromTM(*(localtime(&newtime)));
+ }
fn.result->set_double(date->obj.getTime());
}
void date_setutcmilliseconds(const fn_call& fn) {
- assert(fn.nargs == 1);
date_as_object* date = ensure_date_object(fn.this_ptr);
+
+ // assert(fn.nargs == 1);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
date->obj.millisecond = (long int)(fn.arg(0).to_number());
+ if (fn.nargs > 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than one argument");
+ )
+ }
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
void date_setutcminutes(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 3);
date_as_object* date = ensure_date_object(fn.this_ptr);
+
+ // assert(fn.nargs >= 1 && fn.nargs <= 3);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
// Seconds (value between 0 and 59) won't be affected by timezone
date->obj.minute = (long int)(fn.arg(0).to_number());
if (fn.nargs >= 2) date->obj.second = (long int)(fn.arg(1).to_number());
if (fn.nargs >= 3) date->obj.millisecond = (long
int)(fn.arg(2).to_number());
+ if (fn.nargs > 3) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than three arguments");
+ )
+ }
// Setting milliseconds to less than 0 or more than 999 affects seconds
+
+ // TODO: both of these lines are wrong for negative values
date->obj.second += date->obj.millisecond / 1000;
date->obj.millisecond = date->obj.millisecond % 1000;
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
void date_setutcmonth(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 2);
date_as_object* date = ensure_date_object(fn.this_ptr);
+ // assert(fn.nargs >= 1 && fn.nargs <= 2);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
tm utctime = date->obj.convertUTC();
// Set year to our new UTC date
utctime.tm_mon = int(fn.arg(0).to_number());
if (fn.nargs >= 2)
utctime.tm_mday = (long int)(fn.arg(1).to_number());
+ if (fn.nargs > 2) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than two arguments");
+ )
+ }
// Convert back from UTC to local time
utctime.tm_min += date->obj.minutesEast;
@@ -668,27 +833,54 @@
// Normalize the time, then set as this object's new time
time_t newtime = mktime(&utctime);
date->obj.setFromTM(*(localtime(&newtime)));
-
+ }
fn.result->set_double(date->obj.getTime());
}
void date_setutcseconds(const fn_call& fn) {
- assert(fn.nargs >= 1 && fn.nargs <= 2);
date_as_object* date = ensure_date_object(fn.this_ptr);
+
+ // assert(fn.nargs >= 1 && fn.nargs <= 2);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
// Seconds (value between 0 and 59) won't be affected by timezone
date->obj.second = (long int)(fn.arg(0).to_number());
- if (fn.nargs >= 2) date->obj.millisecond = (long
int)(fn.arg(1).to_number());
+ if (fn.nargs >= 2)
+ date->obj.millisecond = (long int)(fn.arg(1).to_number());
+ if (fn.nargs > 2) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than two arguments");
+ )
+ }
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
+
void date_setyear(const fn_call& fn) {
- assert(fn.nargs == 1);
date_as_object* date = ensure_date_object(fn.this_ptr);
+
+ // assert(fn.nargs == 1);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ } else {
date->obj.year = (long int)(fn.arg(0).to_number());
+ if (fn.nargs > 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " has more than two arguments");
+ )
+ }
date->obj.Normalize();
+ }
fn.result->set_double(date->obj.getTime());
}
+
void date_tostring(const fn_call& fn) {
// TODO: I have no idea what the real flash player does, but at least
this
// gives something functional for now. Tried to mimic the "date" command
Index: server/asobj/Global.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Global.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- server/asobj/Global.cpp 1 Feb 2007 20:45:52 -0000 1.38
+++ server/asobj/Global.cpp 1 Feb 2007 23:18:21 -0000 1.39
@@ -18,7 +18,7 @@
// Implementation of the Global ActionScript Object
-/* $Id: Global.cpp,v 1.38 2007/02/01 20:45:52 martinwguy Exp $ */
+/* $Id: Global.cpp,v 1.39 2007/02/01 23:18:21 martinwguy Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -67,6 +67,20 @@
#include "xml.h"
#include "xmlsocket.h"
+// Common code to warn and return if a required single arg is not present
+// and to warn if there are extra args.
+#define ASSERT_FN_ARGS_IS_1 \
+ if (fn.nargs < 1) {
\
+ IF_VERBOSE_ASCODING_ERRORS( \
+ log_aserror(__FUNCTION__ " needs one argument"); \
+ ) \
+ return; \
+ } \
+ IF_VERBOSE_ASCODING_ERRORS(
\
+ if (fn.nargs > 1) \
+ log_aserror(__FUNCTION__ " has more than one argument"); \
+ )
+
using namespace std;
namespace gnash {
@@ -76,35 +90,13 @@
static void
as_global_trace(const fn_call& fn)
{
- assert(fn.nargs >= 1);
-
-// @@ NOTHING should get special treatment,
-// as_value::to_string() will take care of everything
-#if 0
- // Special case for objects: try the toString() method.
- if (fn.arg(0).get_type() == as_value::OBJECT)
- {
- as_object* obj = fn.arg(0).to_object();
- assert(obj);
-
- as_value method;
- if (obj->get_member("toString", &method)
- && method.is_function())
- {
- as_value result = call_method0(method, fn.env, obj);
- log_msg("%s\n", result.to_string());
-
- return;
- }
- }
-#endif
+ ASSERT_FN_ARGS_IS_1
// Log our argument.
//
// @@ what if we get extra args?
//
- // @@ Array gets special treatment.
- // @@ NOTHING should get special treatment,
+ // @@ Nothing needs special treatment,
// as_value::to_string() will take care of everything
const char* arg0 = fn.arg(0).to_string();
log_msg("%s\n", arg0);
@@ -114,7 +106,7 @@
static void
as_global_isnan(const fn_call& fn)
{
- assert(fn.nargs == 1);
+ ASSERT_FN_ARGS_IS_1
fn.result->set_bool(fn.arg(0).is_nan());
}
@@ -122,7 +114,7 @@
static void
as_global_isfinite(const fn_call& fn)
{
- assert(fn.nargs == 1);
+ ASSERT_FN_ARGS_IS_1
fn.result->set_bool(fn.arg(0).is_finite());
}
@@ -147,7 +139,7 @@
const string escapees = " \"#$%&+,/:;<=>address@hidden|}~";
const string hexdigits = "0123456789ABCDEF";
- assert(fn.nargs == 1);
+ ASSERT_FN_ARGS_IS_1
string input = fn.arg(0).to_string();
@@ -175,7 +167,7 @@
static void
as_global_unescape(const fn_call& fn)
{
- assert(fn.nargs == 1);
+ ASSERT_FN_ARGS_IS_1
string input = fn.arg(0).to_string();
int hexcode;
@@ -207,7 +199,7 @@
static void
as_global_parsefloat(const fn_call& fn)
{
- assert(fn.nargs == 1);
+ ASSERT_FN_ARGS_IS_1
float result;
@@ -222,7 +214,17 @@
static void
as_global_parseint(const fn_call& fn)
{
- assert(fn.nargs == 2 || fn.nargs == 1);
+ // assert(fn.nargs == 2 || fn.nargs == 1);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs at least one argument");
+ )
+ return;
+ }
+ IF_VERBOSE_ASCODING_ERRORS(
+ if (fn.nargs > 2)
+ log_aserror(__FUNCTION__ " has more than two arguments");
+ )
// Make sure our argument is the correct type
if (fn.nargs > 1)
@@ -324,8 +326,21 @@
//log_msg("ASSetPropFlags called with %d args", fn.nargs);
// Check the arguments
- assert(fn.nargs == 3 || fn.nargs == 4);
- assert((version == 5) ? (fn.nargs == 3) : true);
+ // assert(fn.nargs == 3 || fn.nargs == 4);
+ // assert((version == 5) ? (fn.nargs == 3) : true);
+
+ if (fn.nargs < 3) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs at least three arguments");
+ )
+ return;
+ }
+ IF_VERBOSE_ASCODING_ERRORS(
+ if (fn.nargs > 4)
+ log_aserror(__FUNCTION__ " has more than four arguments");
+ if (version == 5 && fn.nargs == 4)
+ log_aserror(__FUNCTION__ " has four arguments in a SWF version 5
movie");
+ )
// ASSetPropFlags(obj, props, n, allowFalse=false)
Index: server/asobj/string.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/string.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- server/asobj/string.cpp 18 Jan 2007 22:53:22 -0000 1.13
+++ server/asobj/string.cpp 1 Feb 2007 23:18:21 -0000 1.14
@@ -18,7 +18,7 @@
//
//
-/* $Id: string.cpp,v 1.13 2007/01/18 22:53:22 strk Exp $ */
+/* $Id: string.cpp,v 1.14 2007/02/01 23:18:21 martinwguy Exp $ */
// Implementation of ActionScript String class.
@@ -156,10 +156,7 @@
tu_string returnstring(newstr);
fn.result->set_tu_string(returnstring);
- delete[] newstr;
-
- //FIXME: is the "delete newstr[];" okay ?
- // Because I don't know if tu_string copies newstr or not. Michael
Meier 2006/11/21
+ delete[] newstr; // because tu_string copies newstr
}
// 1st param: start_index, 2nd param: end_index
@@ -184,7 +181,13 @@
end = iclamp(end, 0, utf8_len);
}
- assert(end >= start);
+ if (end < start) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_error("string.slice() called with end < start");
+ )
+ // Swap start and end, cos that's what substr does
+ swap(&start, &end);
+ }
fn.result->set_tu_string(this_string.utf8_substring(start, end));
return;
@@ -354,7 +357,6 @@
}
if (end < start) swap(&start, &end); // dumb, but that's what the
docs say
- assert(end >= start);
fn.result->set_tu_string(this_string.utf8_substring(start, end));
return;
@@ -416,7 +418,18 @@
tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
assert(this_string_ptr);
- assert(fn.nargs == 1);
+ // assert(fn.nargs == 1);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror("string.charCodeAt needs one argument");
+ )
+ fn.result->set_nan(); // Same as for out-of-range arg
+ return;
+ }
+ IF_VERBOSE_ASCODING_ERRORS(
+ if (fn.nargs > 1)
+ log_aserror("string.charCodeAt has more than one argument");
+ )
int index = static_cast<int>(fn.arg(0).to_number());
if (index >= 0 && index < this_string_ptr->m_string.utf8_length())
@@ -436,7 +449,18 @@
tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
assert(this_string_ptr);
- assert(fn.nargs == 1);
+ // assert(fn.nargs == 1);
+ if (fn.nargs < 1) {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(__FUNCTION__ " needs one argument");
+ )
+ fn.result->set_tu_string(""); // Same as for out-of-range arg
+ return;
+ }
+ IF_VERBOSE_ASCODING_ERRORS(
+ if (fn.nargs > 1)
+ log_aserror(__FUNCTION__ " has more than one argument");
+ )
int index = static_cast<int>(fn.arg(0).to_number());
if (index >= 0 && index < this_string_ptr->m_string.utf8_length())
- [Gnash-commit] gnash ChangeLog server/asobj/Date.cpp server/as...,
Martin Guy <=