@@ 61,22 61,24 @@ fn scan_double(h: io::handle) (f64 | error) = {
fn scan_byte_array(h: io::handle) ([]i8 | error) = {
let length = scan_int(h)?: size;
- let buf = alloc([0i8...], length);
- for (let i = 0z; i < length; i += 1) {
- match (scan_byte(h)) {
- case let err: error => {
- free(buf);
- return err;
- };
- case let val: i8 =>
- buf[i] = val;
- };
+
+ if (length == 0) {
+ return []: []i8;
};
+
+ let buf = alloc([0i8...], length);
+ scan_buf(h, buf: []u8)?;
+
return buf;
};
fn scan_int_array(h: io::handle) ([]i32 | error) = {
let length = scan_int(h)?: size;
+
+ if (length == 0) {
+ return []: []i32;
+ };
+
let buf = alloc([0i32...], length);
for (let i = 0z; i < length; i += 1) {
match (scan_int(h)) {
@@ 93,6 95,11 @@ fn scan_int_array(h: io::handle) ([]i32 | error) = {
fn scan_long_array(h: io::handle) ([]i64 | error) = {
let length = scan_int(h)?: size;
+
+ if (length == 0) {
+ return []: []i64;
+ };
+
let buf = alloc([0i64...], length);
for (let i = 0z; i < length; i += 1) {
@@ 112,6 119,11 @@ fn scan_long_array(h: io::handle) ([]i64 | error) = {
fn scan_list(h: io::handle) (list | error) = {
let typ = scan_type(h)?;
let length = scan_int(h)?: size;
+
+ if (length == 0) {
+ return (tagtype::END, []: []payload);
+ };
+
let list: []payload = alloc([end...], length);
for (let i = 0z; i < length; i += 1) {