Fix io::default_read_to_end uses of read_buf · qinheping/verify-rust-std@f342675 (original) (raw)

`@@ -474,18 +474,28 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(

`

474

474

`}

`

475

475

``

476

476

`let mut cursor = read_buf.unfilled();

`

477

``

`-

loop {

`

``

477

`+

let result = loop {

`

478

478

`match r.read_buf(cursor.reborrow()) {

`

479

``

`-

Ok(()) => break,

`

480

479

`Err(e) if e.is_interrupted() => continue,

`

481

``

`-

Err(e) => return Err(e),

`

``

480

`+

// Do not stop now in case of error: we might have received both data

`

``

481

`+

// and an error

`

``

482

`+

res => break res,

`

482

483

`}

`

483

``

`-

}

`

``

484

`+

};

`

484

485

``

485

486

`let unfilled_but_initialized = cursor.init_ref().len();

`

486

487

`let bytes_read = cursor.written();

`

487

488

`let was_fully_initialized = read_buf.init_len() == buf_len;

`

488

489

``

``

490

`+

// SAFETY: BorrowedBuf's invariants mean this much memory is initialized.

`

``

491

`+

unsafe {

`

``

492

`+

let new_len = bytes_read + buf.len();

`

``

493

`+

buf.set_len(new_len);

`

``

494

`+

}

`

``

495

+

``

496

`+

// Now that all data is pushed to the vector, we can fail without data loss

`

``

497

`+

result?;

`

``

498

+

489

499

`if bytes_read == 0 {

`

490

500

`return Ok(buf.len() - start_len);

`

491

501

`}

`

`@@ -499,12 +509,6 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>(

`

499

509

`// store how much was initialized but not filled

`

500

510

` initialized = unfilled_but_initialized;

`

501

511

``

502

``

`-

// SAFETY: BorrowedBuf's invariants mean this much memory is initialized.

`

503

``

`-

unsafe {

`

504

``

`-

let new_len = bytes_read + buf.len();

`

505

``

`-

buf.set_len(new_len);

`

506

``

`-

}

`

507

``

-

508

512

`// Use heuristics to determine the max read size if no initial size hint was provided

`

509

513

`if size_hint.is_none() {

`

510

514

`// The reader is returning short reads but it doesn't call ensure_init().

`