Fix memory corruption as of issue #2

This commit is contained in:
A. Fachat 2014-08-19 23:28:49 +02:00
parent 3ce489442c
commit 7e71d01a9a
3 changed files with 24 additions and 27 deletions

View File

@ -2,7 +2,7 @@
#
CC = gcc
LD = gcc
CFLAGS = -O2 -W -Wall -pedantic -ansi
CFLAGS = -O2 -W -Wall -pedantic -std=c99 -g
LDFLAGS = -lc
# for DOS?

View File

@ -214,13 +214,20 @@ int pp_endif(char *t)
/* stub for handling CPP directives */
int pp_cpp(char *t) {
if(sscanf(t, " %d \"%s\"", &filep->fline, filep->fname) == 2) {
char *fname = NULL;
if(sscanf(t, " %d \"%ms\"", &filep->fline, &fname) == 2) {
/* massage it into our parameters and drop last quote */
char *u = "";
filep->fline--;
if((u = (char *)strrchr(filep->fname, '"')))
if((u = (char *)strrchr(fname, '"')))
*u = '\0';
// overwrite the original filename
// this may create a memory leak, but we do not know
// whether the file name has already been used in the cross
// reference list. So we just accept that...
filep->fname = fname;
return (0);
} else {
return(E_SYNTAX);

View File

@ -1,32 +1,22 @@
# 1 "over.c"
lda #1
jmp buggy
rts
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "over.c"
# 13 "over.c"
lda #1
jmp buggy
rts
# 1 "over.h" 1
fuzz lda #5
sta $0400
bne fuzz
rts
fuzz lda #5
sta $0400
bne fuzz
rts
lda @$c0c0c0
# 17 "over.c" 2
lda @$c0c0c0
# 18 "over.c" 2