summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-01-23 17:58:05 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-01-23 17:59:37 +0200
commit425f952a1e18e64f19a0330c9c54a3eccb3c4ff7 (patch)
tree53b2586b12686970fd9ebb556479c47a027e69cc
parent220d21e1bfad2ce95e9550b654c3565b85f41c86 (diff)
downloadmicropython-425f952a1e18e64f19a0330c9c54a3eccb3c4ff7.tar.gz
micropython-425f952a1e18e64f19a0330c9c54a3eccb3c4ff7.zip
stream: Fix readall() implementation in respect to NUL terminator bytes.
After vstr refactor. Fixes #1084.
-rw-r--r--py/stream.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/py/stream.c b/py/stream.c
index 3415b74b93..921459a8d4 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -255,7 +255,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
vstr_t vstr;
vstr_init(&vstr, DEFAULT_BUFFER_SIZE);
char *p = vstr.buf;
- mp_uint_t current_read = DEFAULT_BUFFER_SIZE - 1; // save 1 byte for null termination
+ mp_uint_t current_read = DEFAULT_BUFFER_SIZE;
while (true) {
int error;
mp_uint_t out_sz = o->type->stream_p->read(self_in, p, current_read, &error);
@@ -280,7 +280,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
p += out_sz;
} else {
p = vstr_extend(&vstr, DEFAULT_BUFFER_SIZE);
- current_read = DEFAULT_BUFFER_SIZE - 1; // save 1 byte for null termination
+ current_read = DEFAULT_BUFFER_SIZE;
if (p == NULL) {
// TODO
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError/*&mp_type_RuntimeError*/, "Out of memory"));
@@ -289,7 +289,6 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
}
vstr.len = total_size;
- vstr.buf[vstr.len] = '\0';
return mp_obj_new_str_from_vstr(STREAM_CONTENT_TYPE(o->type->stream_p), &vstr);
}