@@ -697,11 +697,18 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
struct bfd_section *asect = p->the_bfd_section;
bfd *abfd = asect->owner;
+ /* To deals with possible overflow where p->endaddr is 0,
+ because of section ends on max of CORE_ADDR, copy section
+ addr and endaddr to ULONGEST type. Recover section length
+ first, and use it to determine section_endaddr. */
+ ULONGEST section_addr = p->addr;
+ ULONGEST section_endaddr = section_addr + (p->endaddr - p->addr);
+
if (section_name && strcmp (section_name, asect->name) != 0)
continue; /* not the section we need. */
- if (memaddr >= p->addr)
+ if (memaddr >= section_addr)
{
- if (memend <= p->endaddr)
+ if (memend <= section_endaddr)
{
/* Entire transfer is within this section. */
if (writebuf)
@@ -721,7 +728,7 @@ section_table_xfer_memory_partial (gdb_byte *readbuf, const gdb_byte *writebuf,
else
return TARGET_XFER_EOF;
}
- else if (memaddr >= p->endaddr)
+ else if (memaddr >= section_endaddr)
{
/* This section ends before the transfer starts. */
continue;