From 0d3401058d83b469ef7be63d066ca9bed819735c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Mon, 24 Apr 2017 01:29:40 +0200 Subject: [PATCH] Check max section sizes in rgblink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The max size of some section types depends on the flags passed to rgblink. Instead of doing in rgbasm some checks (for the sections with fixed size) and others in rgblink, all checks are now done in rgblink. Signed-off-by: Antonio Niño Díaz --- src/link/object.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/link/object.c b/src/link/object.c index 3a8d1a5d..9da981ac 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -169,6 +169,42 @@ obj_ReadRGBSection(FILE * f) } } + unsigned int maxsize = 0; + + /* Verify that the section isn't too big */ + switch (pSection->Type) + { + case SECT_ROM0: + maxsize = (options & OPT_TINY) ? 0x8000 : 0x4000; + break; + case SECT_ROMX: + maxsize = 0x4000; + break; + case SECT_VRAM: + case SECT_SRAM: + maxsize = 0x2000; + break; + case SECT_WRAM0: + maxsize = (options & OPT_CONTWRAM) ? 0x2000 : 0x1000; + break; + case SECT_WRAMX: + maxsize = 0x1000; + break; + case SECT_OAM: + maxsize = 0xA0; + break; + case SECT_HRAM: + maxsize = 0x7F; + break; + default: + errx(1, "Section \"%s\" has an invalid section type.", pzName); + break; + } + if (pSection->nByteSize > maxsize) { + errx(1, "Section \"%s\" is bigger than the max size for that type: 0x%X > 0x%X", + pzName, pSection->nByteSize, maxsize); + } + if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) { /* * These sectiontypes contain data...