Oh crap, let's make ObjectOutputStream protect against fuckup, too.
Note that we're using ints instead of units for offset/length. Does anyone really need a byte array larger than 2^31? And if so, wouldn't you then also be within sight of busting 2^32? Why not make it a Number and support up to 2^53? Number is no guarantee of a desire for a floating-point value in the flash libraries, see Graphics.lineStyle()'s first parameter. Actionscript, you fail for not having long. And... I said I wasn't going to bitch at Adobe/Macromedia any more but this is a total FAIL. 0 is a valid length. Everyone knows this. Can you imagine if they picked a different constant? length: the number of bytes to read, unless it's 9, in which case it reads *all* the bytes. Your code should check to see if you're about to read 9 bytes, and instead read 8 in one go and then a follow-on byte. uint.MAX_VALUE would have made tons more sense. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5968 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -202,8 +202,7 @@ public class ObjectInputStream
|
||||
* Read bytes into the byte array. If length is not specified, then
|
||||
* enough bytes to fill the array (from the offset) are read.
|
||||
*/
|
||||
public function readBytes (bytes :ByteArray, offset :uint = 0,
|
||||
length :int = -1) :void
|
||||
public function readBytes (bytes :ByteArray, offset :int = 0, length :int = -1) :void
|
||||
//throws IOError
|
||||
{
|
||||
// if no length specified then fill the ByteArray
|
||||
|
||||
@@ -164,11 +164,15 @@ public class ObjectOutputStream
|
||||
_targ.writeByte(value);
|
||||
}
|
||||
|
||||
public function writeBytes (bytes :ByteArray, offset :uint=0,
|
||||
length :uint = 0) :void
|
||||
public function writeBytes (bytes :ByteArray, offset :int = 0, length :int = -1) :void
|
||||
//throws IOError
|
||||
{
|
||||
_targ.writeBytes(bytes, offset, length);
|
||||
if (length == -1) {
|
||||
length = bytes.length - offset;
|
||||
}
|
||||
if (length > 0) {
|
||||
_targ.writeBytes(bytes, offset, length);
|
||||
}
|
||||
}
|
||||
|
||||
public function writeDouble (value :Number) :void
|
||||
|
||||
Reference in New Issue
Block a user