# HG changeset patch # User lost # Date 1232683417 0 # Node ID 4ac96c697ef0886d2fe9cef06f7b7fbf1119d786 # Parent 6084a3859fb4e887385bbe63b83be2adbfd4fd19 Corrected errors with parsing script and object files diff -r 6084a3859fb4 -r 4ac96c697ef0 lwlink/trunk/src/link.c --- a/lwlink/trunk/src/link.c Thu Jan 22 02:14:52 2009 +0000 +++ b/lwlink/trunk/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 6084a3859fb4 -r 4ac96c697ef0 lwlink/trunk/src/readfiles.c --- a/lwlink/trunk/src/readfiles.c Thu Jan 22 02:14:52 2009 +0000 +++ b/lwlink/trunk/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 6084a3859fb4 -r 4ac96c697ef0 lwlink/trunk/src/script.c --- a/lwlink/trunk/src/script.c Thu Jan 22 02:14:52 2009 +0000 +++ b/lwlink/trunk/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"