Fix LoadImage at 4k boundary LoadImage can work on images as multiples of 4k, resulting the last segment with 0 length. Take care of this case PiperOrigin-RevId: 621220520
diff --git a/sim/kelvin_top.cc b/sim/kelvin_top.cc index dcd2b79..5bb2395 100644 --- a/sim/kelvin_top.cc +++ b/sim/kelvin_top.cc
@@ -688,6 +688,7 @@ image_file.read(buffer, kBufferSize); // Get the number of bytes that was read. gcount = image_file.gcount(); + if (gcount == 0) break; // Write to the simulator memory. auto res = WriteMemory(load_address, buffer, gcount); // Check that the write succeeded, increment address if it did. @@ -698,7 +699,7 @@ return absl::InternalError("Failed to write all the bytes"); } load_address += gcount; - } while (image_file.good() && (gcount > 0)); + } while (image_file.good()); image_file.close(); return absl::OkStatus(); }