[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r9848: Fix a bug in readNetworkLong
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r9848: Fix a bug in readNetworkLong and amf0_read_value. |
Date: |
Fri, 26 Sep 2008 10:36:36 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9848
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2008-09-26 10:36:36 +0200
message:
Fix a bug in readNetworkLong and amf0_read_value.
modified:
libcore/as_value.cpp
------------------------------------------------------------
revno: 9844.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Fri 2008-09-26 10:27:33 +0200
message:
Make readNetworkLong return a uint32. Tidy up loops (don't check size() on
each iteration). Split long lines (tabs -> spaces needed still).
modified:
libcore/as_value.cpp
=== modified file 'libcore/as_value.cpp'
--- a/libcore/as_value.cpp 2008-09-18 11:59:44 +0000
+++ b/libcore/as_value.cpp 2008-09-26 08:27:33 +0000
@@ -664,7 +664,7 @@
}
}
- else if(swfversion <= 4)
+ else if (swfversion <= 4)
{
// For SWF4, any valid number before non-numerical
// characters is returned, including exponent, positive
@@ -1586,15 +1586,15 @@
// but that may just be a better compiler.
// Handle non-numeric values.
- if(isNaN(val))
+ if (isNaN(val))
{
return "NaN";
}
- else if(isinf(val))
+ else if (isinf(val))
{
return val < 0 ? "-Infinity" : "Infinity";
}
- else if(val == 0.0 || val == -0.0)
+ else if (val == 0.0 || val == -0.0)
{
return "0";
}
@@ -1842,7 +1842,6 @@
m_type(UNDEFINED)
{
VM& vm = VM::get();
- //int swfVersion = vm.getSWFVersion();
string_table& st = vm.getStringTable();
switch (el.getType()) {
@@ -1912,7 +1911,7 @@
#endif
as_object* obj = new as_object(getObjectInterface());
if (el.propertySize()) {
- for (size_t i=0; i < el.propertySize(); i++) {
+ for (size_t i = 0, e = el.propertySize(); i != e; ++i) {
const amf::Element *prop = el.getProperty(i);
if (prop == 0) {
break;
@@ -1934,9 +1933,9 @@
#ifdef GNASH_DEBUG_AMF_DESERIALIZE
log_debug("as_value(Element&) : AMF type ECMA_ARRAY");
#endif
- Array_as* obj = new Array_as();
+ Array_as* obj = new Array_as;
if (el.propertySize()) {
- for (size_t i=0; i < el.propertySize(); i++) {
+ for (size_t i = 0, e = el.propertySize(); i != e; ++i) {
const amf::Element *prop = el.getProperty(i);
if (prop == 0) {
break;
@@ -1955,11 +1954,11 @@
#ifdef GNASH_DEBUG_AMF_DESERIALIZE
log_debug("as_value(Element&) : AMF type STRICT_ARRAY");
#endif
- Array_as* obj = new Array_as();
+ Array_as* obj = new Array_as;
size_t len = el.propertySize();
obj->resize(len);
- for (size_t i=0; i < el.propertySize(); i++) {
+ for (size_t i = 0, e = el.propertySize(); i != e; ++i) {
const amf::Element *prop = el.getProperty(i);
if (prop == 0) {
break;
@@ -2115,7 +2114,7 @@
return s;
}
-static boost::uint16_t
+static boost::uint32_t
readNetworkLong(const boost::uint8_t* buf) {
boost::uint32_t s = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
return s;
@@ -2140,25 +2139,24 @@
amf0_read_value(boost::uint8_t *&b, boost::uint8_t *end, as_value& ret, int
inType,
std::vector<as_object*>& objRefs, VM& vm)
{
- boost::uint16_t si;
- boost::uint16_t li;
- double dub;
int amf_type;
- if(b > end) {
+ if (b > end) {
return false;
}
- if(inType != -1) {
+
+ if (inType != -1) {
amf_type = inType;
- } else {
- if(b < end) {
+ }
+ else {
+ if (b < end) {
amf_type = *b; b += 1;
} else {
return false;
}
}
- switch(amf_type)
+ switch (amf_type)
{
case amf::Element::BOOLEAN_AMF0:
@@ -2173,11 +2171,11 @@
case amf::Element::NUMBER_AMF0:
{
- if(b + 8 > end) {
+ if (b + 8 > end) {
log_error(_("AMF0 read: premature end of input
reading Number type"));
return false;
}
- dub = *(reinterpret_cast<double*>(b)); b += 8;
+ double dub = *(reinterpret_cast<double*>(b)); b += 8;
amf::swapBytes(&dub, 8);
#ifdef GNASH_DEBUG_AMF_DESERIALIZE
log_debug("amf0 read double: %e", dub);
@@ -2188,13 +2186,15 @@
case amf::Element::STRING_AMF0:
{
- if(b + 2 > end) {
- log_error(_("AMF0 read: premature end of input
reading String type"));
+ if (b + 2 > end) {
+ log_error(_("AMF0 read: premature end of input
reading String "
+ " type"));
return false;
}
- si = readNetworkShort(b); b += 2;
- if(b + si > end) {
- log_error(_("AMF0 read: premature end of input
reading String type"));
+ boost::uint16_t si = readNetworkShort(b); b += 2;
+ if (b + si > end) {
+ log_error(_("AMF0 read: premature end of input
reading String "
+ "type"));
return false;
}
@@ -2215,14 +2215,15 @@
boost::intrusive_ptr<Array_as> array(new
Array_as());
objRefs.push_back(array.get());
- li = readNetworkLong(b); b += 4;
+ boost::uint32_t li = readNetworkLong(b); b += 4;
#ifdef GNASH_DEBUG_AMF_DESERIALIZE
log_debug("amf0 starting read of STRICT_ARRAY
with %i elements", li);
#endif
as_value arrayElement;
- for(int i = 0; i < li; ++i)
+ for(size_t i = 0; i < li; ++i)
{
- if ( ! amf0_read_value(b, end,
arrayElement, -1, objRefs, vm) )
+ if ( ! amf0_read_value(b, end,
arrayElement, -1,
+ objRefs, vm) )
{
return false;
}
@@ -2242,7 +2243,10 @@
// (like premature end of buffer) we still get something.
ret.set_as_object(obj);
- li = readNetworkLong(b); b += 4;
+ boost::uint32_t li = readNetworkLong(b); b += 4;
+
+ log_debug("array size: %d", li);
+
// the count specifies array size, so to have that even if
none of the members are indexed
// if short, will be incremented everytime an indexed member
is found
obj->resize(li);
@@ -2258,7 +2262,8 @@
{
if ( b+2 >= end )
{
- log_error("MALFORMED SOL: premature end of ECMA_ARRAY
block");
+ log_error("MALFORMED SOL: premature end of ECMA_ARRAY "
+ "block");
break;
}
boost::uint16_t strlen =
readNetworkShort(b); b+=2;
@@ -2270,12 +2275,13 @@
// expect an object terminator here
if ( *b++ != amf::Element::OBJECT_END_AMF0 )
{
- log_error("MALFORMED SOL: empty member name not
followed by OBJECT_END_AMF0 byte");
+ log_error("MALFORMED SOL: empty member name not "
+ "followed by OBJECT_END_AMF0 byte");
}
break;
}
- std::string name((char*)b, strlen);
+ std::string
name(reinterpret_cast<char*>(b), strlen);
#ifdef GNASH_DEBUG_AMF_DESERIALIZE
log_debug("amf0 ECMA_ARRAY prop name is
%s", name);
@@ -2310,7 +2316,8 @@
std::string keyString;
for(;;)
{
- if ( ! amf0_read_value(b, end, tmp,
amf::Element::STRING_AMF0, objRefs, vm) )
+ if ( ! amf0_read_value(b, end, tmp,
+ amf::Element::STRING_AMF0, objRefs, vm) )
{
return false;
}
@@ -2318,10 +2325,11 @@
if ( keyString.empty() )
{
- if(b < end) {
+ if (b < end) {
b += 1; // AMF0 has a
redundant "object end" byte
} else {
- log_error("AMF buffer
terminated just before object end byte. continueing anyway.");
+ log_error("AMF buffer
terminated just before "
+ "object end byte. continuing anyway.");
}
return true;
}
@@ -2354,7 +2362,7 @@
case amf::Element::REFERENCE_AMF0:
{
- si = readNetworkShort(b); b += 2;
+ boost::uint16_t si = readNetworkShort(b); b += 2;
#ifdef GNASH_DEBUG_AMF_DESERIALIZE
log_debug("readAMF0: reference #%d", si);
#endif
@@ -2386,11 +2394,12 @@
}
bool
-as_value::writeAMF0(SimpleBuffer& buf, std::map<as_object*, size_t>&
offsetTable, VM& vm) const
+as_value::writeAMF0(SimpleBuffer& buf,
+ std::map<as_object*, size_t>& offsetTable, VM& vm) const
{
typedef std::map<as_object*, size_t> OffsetTable;
- assert ( ! is_exception() );
+ assert (!is_exception());
switch (m_type)
{
@@ -2514,7 +2523,7 @@
#endif
buf.appendByte(amf::Element::BOOLEAN_AMF0);
- if(tf) buf.appendByte(1);
+ if (tf) buf.appendByte(1);
else buf.appendByte(0);
return true;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r9848: Fix a bug in readNetworkLong and amf0_read_value.,
Benjamin Wolsey <=