comparison lwlink/trunk/src/readfiles.c @ 124:4ac96c697ef0

Corrected errors with parsing script and object files
author lost
date Fri, 23 Jan 2009 04:03:37 +0000
parents 36ce328df3c3
children 269ef87192ad
comparison
equal deleted inserted replaced
123:6084a3859fb4 124:4ac96c697ef0
86 } 86 }
87 } 87 }
88 88
89 // this macro is used to bail out if we run off the end of the file data 89 // this macro is used to bail out if we run off the end of the file data
90 // while parsing - it keeps the code below cleaner 90 // while parsing - it keeps the code below cleaner
91 #define NEXTBYTE() do { cc++; if (cc >= fn -> filesize) { fprintf(stderr, "%s: invalid file format\n", fn -> filename); exit(1); } } while (0) 91 #define NEXTBYTE() do { cc++; if (cc > fn -> filesize) { fprintf(stderr, "%s: invalid file format\n", fn -> filename); exit(1); } } while (0)
92 // this macro is used to refer to the current byte in the stream 92 // this macro is used to refer to the current byte in the stream
93 #define CURBYTE() (fn -> filedata[cc]) 93 #define CURBYTE() (fn -> filedata[cc < fn -> filesize ? cc : fn -> filesize - 1])
94 // this one will leave the input pointer past the trailing NUL 94 // this one will leave the input pointer past the trailing NUL
95 #define CURSTR() read_lwobj16v0_str(&cc, fn) 95 #define CURSTR() read_lwobj16v0_str(&cc, fn)
96 unsigned char *read_lwobj16v0_str(long *cc1, fileinfo_t *fn) 96 unsigned char *read_lwobj16v0_str(long *cc1, fileinfo_t *fn)
97 { 97 {
98 int cc = *cc1; 98 int cc = *cc1;
183 se -> next = s -> localsyms; 183 se -> next = s -> localsyms;
184 s -> localsyms = se; 184 s -> localsyms = se;
185 se -> sym = fp; 185 se -> sym = fp;
186 se -> offset = val; 186 se -> offset = val;
187 } 187 }
188 188 // skip terminating NUL
189 NEXTBYTE();
190
189 // now parse the exported symbol table 191 // now parse the exported symbol table
190 while (CURBYTE()) 192 while (CURBYTE())
191 { 193 {
192 fp = CURSTR(); 194 fp = CURSTR();
193 195
203 se -> next = s -> exportedsyms; 205 se -> next = s -> exportedsyms;
204 s -> localsyms = se; 206 s -> localsyms = se;
205 se -> sym = fp; 207 se -> sym = fp;
206 se -> offset = val; 208 se -> offset = val;
207 } 209 }
210 // skip terminating NUL
211 NEXTBYTE();
208 212
209 // now parse the incomplete references and make a list of 213 // now parse the incomplete references and make a list of
210 // external references that need resolution 214 // external references that need resolution
211 while (CURBYTE()) 215 while (CURBYTE())
212 { 216 {
267 } 271 }
268 lw_expr_stack_push(rp -> expr, term); 272 lw_expr_stack_push(rp -> expr, term);
269 lw_expr_term_free(term); 273 lw_expr_term_free(term);
270 } 274 }
271 } 275 }
272 // skip the NUL terminatin 276 // skip the NUL terminating the relocations
273 NEXTBYTE(); 277 NEXTBYTE();
274 278
275 // now set code location and size and verify that the file 279 // now set code location and size and verify that the file
276 // contains data going to the end of the code (if !SECTION_BSS) 280 // contains data going to the end of the code (if !SECTION_BSS)
277 s -> codesize = CURBYTE() << 8; 281 s -> codesize = CURBYTE() << 8;