avr_loadcode(): If too much code, bail out instead of crashing.
authorSami Liedes <sliedes@cc.hut.fi>
Sat, 19 Feb 2011 03:25:53 +0000 (05:25 +0200)
committerMichel Pollet <buserror@gmail.com>
Mon, 21 Feb 2011 23:17:38 +0000 (23:17 +0000)
Check that the code to be loaded actually fits in the flash.

Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
simavr/sim/sim_avr.c

index 80c888b..d5611ba 100644 (file)
@@ -150,6 +150,11 @@ void avr_set_console_register(avr_t * avr, avr_io_addr_t addr)
 
 void avr_loadcode(avr_t * avr, uint8_t * code, uint32_t size, uint32_t address)
 {
+       if (size > avr->flashend+1) {
+               fprintf(stderr, "avr_loadcode(): Attempted to load code of size %d but flash size is only %d.\n",
+                       size, avr->flashend+1);
+               abort();
+       }
        memcpy(avr->flash + address, code, size);
 }