From 3ce489442cbc0c165487a9883def7230798e308c Mon Sep 17 00:00:00 2001 From: "A. Fachat" Date: Fri, 4 Oct 2013 14:13:54 +0200 Subject: [PATCH 1/2] fixed incompatibility with system getline() --- xa/src/xa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xa/src/xa.c b/xa/src/xa.c index 3a54e6c..1bebcf8 100644 --- a/xa/src/xa.c +++ b/xa/src/xa.c @@ -87,7 +87,7 @@ static int pass2(void); static int puttmp(int); static int puttmps(signed char *, int); static void chrput(int); -static int getline(char *); +static int xagetline(char *); static void lineout(void); static long ga_p1(void); static long gm_p1(void); @@ -763,7 +763,7 @@ static int pass1(void) temp_er = 0; /*FIXIT*/ - while(!(er=getline(s))) + while(!(er=xagetline(s))) { er=t_p1((signed char*)s,o,&l,&al); switch(segment) { @@ -1002,7 +1002,7 @@ static int puttmps(signed char *s, int l) static char l[MAXLINE]; -static int getline(char *s) +static int xagetline(char *s) { static int ec; From 7e71d01a9a5d2b740031bc07f4b9ae8c0df6bdc5 Mon Sep 17 00:00:00 2001 From: "A. Fachat" Date: Tue, 19 Aug 2014 23:28:49 +0200 Subject: [PATCH 2/2] Fix memory corruption as of issue #2 --- xa/Makefile | 2 +- xa/src/xap.c | 11 +++++++++-- xa/tests/cpp/over.asm | 38 ++++++++++++++------------------------ 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/xa/Makefile b/xa/Makefile index 78ca224..92a1610 100644 --- a/xa/Makefile +++ b/xa/Makefile @@ -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? diff --git a/xa/src/xap.c b/xa/src/xap.c index da8e3c3..a261a5d 100644 --- a/xa/src/xap.c +++ b/xa/src/xap.c @@ -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); diff --git a/xa/tests/cpp/over.asm b/xa/tests/cpp/over.asm index c8cc252..96598e4 100644 --- a/xa/tests/cpp/over.asm +++ b/xa/tests/cpp/over.asm @@ -1,32 +1,22 @@ # 1 "over.c" - - - - - - - - - - - - - lda #1 - jmp buggy - rts +# 1 "" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 1 "" 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