File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
9797 }
9898 int error ;
9999 mp_int_t out_sz = o -> type -> stream_p -> read (o , p , more_bytes , & error );
100- if (out_sz == -1 ) {
100+ if (out_sz < 0 ) {
101101 vstr_cut_tail_bytes (& vstr , more_bytes );
102102 if (is_nonblocking_error (error )) {
103103 // With non-blocking streams, we read as much as we can.
@@ -113,11 +113,13 @@ STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
113113 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError , "[Errno %d]" , error ));
114114 }
115115
116- if (out_sz == 0 ) {
116+ if (out_sz < more_bytes ) {
117117 // Finish reading.
118118 // TODO what if we have read only half a non-ASCII char?
119- vstr_cut_tail_bytes (& vstr , more_bytes );
120- break ;
119+ vstr_cut_tail_bytes (& vstr , more_bytes - out_sz );
120+ if (out_sz == 0 ) {
121+ break ;
122+ }
121123 }
122124
123125 // count chars from bytes just read
You can’t perform that action at this time.
0 commit comments