# HG changeset patch # User lost # Date 1232683417 0 # Node ID be1abc4ac114f7500991c063f5802bc7d2360886 # Parent 10cc87f4b16c9062f7dd0021dfee99b96d8686e1 Corrected errors with parsing script and object files diff -r 10cc87f4b16c -r be1abc4ac114 src/link.c --- a/src/link.c Thu Jan 22 02:14:52 2009 +0000 +++ b/src/link.c Fri Jan 23 04:03:37 2009 +0000 @@ -231,7 +231,7 @@ lw_expr_stack_free(s); } - for (sn = 0; nsects; sn++) + for (sn = 0; sn < nsects; sn++) { for (rl = sectlist[sn].ptr -> incompletes; rl; rl = rl -> next) { diff -r 10cc87f4b16c -r be1abc4ac114 src/readfiles.c --- a/src/readfiles.c Thu Jan 22 02:14:52 2009 +0000 +++ b/src/readfiles.c Fri Jan 23 04:03:37 2009 +0000 @@ -88,9 +88,9 @@ // this macro is used to bail out if we run off the end of the file data // while parsing - it keeps the code below cleaner -#define NEXTBYTE() do { cc++; if (cc >= fn -> filesize) { fprintf(stderr, "%s: invalid file format\n", fn -> filename); exit(1); } } while (0) +#define NEXTBYTE() do { cc++; if (cc > fn -> filesize) { fprintf(stderr, "%s: invalid file format\n", fn -> filename); exit(1); } } while (0) // this macro is used to refer to the current byte in the stream -#define CURBYTE() (fn -> filedata[cc]) +#define CURBYTE() (fn -> filedata[cc < fn -> filesize ? cc : fn -> filesize - 1]) // this one will leave the input pointer past the trailing NUL #define CURSTR() read_lwobj16v0_str(&cc, fn) unsigned char *read_lwobj16v0_str(long *cc1, fileinfo_t *fn) @@ -185,7 +185,9 @@ se -> sym = fp; se -> offset = val; } - + // skip terminating NUL + NEXTBYTE(); + // now parse the exported symbol table while (CURBYTE()) { @@ -205,6 +207,8 @@ se -> sym = fp; se -> offset = val; } + // skip terminating NUL + NEXTBYTE(); // now parse the incomplete references and make a list of // external references that need resolution @@ -269,7 +273,7 @@ lw_expr_term_free(term); } } - // skip the NUL terminatin + // skip the NUL terminating the relocations NEXTBYTE(); // now set code location and size and verify that the file diff -r 10cc87f4b16c -r be1abc4ac114 src/script.c --- a/src/script.c Thu Jan 22 02:14:52 2009 +0000 +++ b/src/script.c Fri Jan 23 04:03:37 2009 +0000 @@ -35,7 +35,7 @@ // the built-in DECB target linker script static char *decb_script = - "section init load at 2000\n" + "section init load 2000\n" "section code\n" "section *,!bss\n" "section *,bss\n" @@ -44,7 +44,7 @@ // the built-in RAW target linker script static char *raw_script = - "section init load at 0000\n" + "section init load 0000\n" "section code\n" "section *,!bss\n" "section *,bss\n"