Skip to content

The number reader methods in should raise a condition if not enough bytes could be read #8834

Closed
@rapha

Description

@rapha

Currently the various number reader methods defined in

std::rt::io::extensions::ReaderByteConversions

are based on read_u8_ and read_i8_ which simply return 0 if the byte could not be read. This means that the user can silently read bad values, e.g.

$ rusti
rusti> use std::rt::io::Reader; 
rusti> use std::rt::io::extensions::ReaderUtil;
rusti> use std::rt::io::extensions::ReaderByteConversions;
rusti> use std::rt::io::mem::MemReader; 
rusti> MemReader::new(~[1]).read_be_u32_()
16777216 

I suggest that a read_u8_ and read_i8_ should raise an EndOfFile, similarly to ReaderUtil::push_bytes, so the user can handle that case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions