From 1aeafebe2c6227cf27f1e9dad5e07ae0590ee789 Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Sat, 10 May 2003 22:41:53 +0000 Subject: [PATCH] * src/SDCCmain.c (linkEdit): fixed buffer overflow for gbz80 * support/regression/Makefile: inter-port-clean is no longer nesessary, the temp files are in the port dir; clean the gen/test directory when generating new test.c * support/regression/ports/host/spec.mk: defined OBJEXT for target clean * support/regression/tests/vaargs.c: fixed gcc 3.3 warning * support/regression/tests/zeropad.c: added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2606 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 12 +++++- src/SDCCmain.c | 57 +++++++++++---------------- support/regression/Makefile | 27 ++++++------- support/regression/ports/host/spec.mk | 1 + support/regression/tests/vaargs.c | 13 ++++-- support/regression/tests/zeropad.c | 35 ++++++++++++++++ 6 files changed, 93 insertions(+), 52 deletions(-) create mode 100644 support/regression/tests/zeropad.c diff --git a/ChangeLog b/ChangeLog index f4e15821..3cddcb34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-05-04 Bernhard Held + + * src/SDCCmain.c (linkEdit): fixed buffer overflow for gbz80 + * support/regression/Makefile: inter-port-clean is no longer nesessary, the + temp files are in the port dir; clean the gen/test directory when + generating new test.c + * support/regression/ports/host/spec.mk: defined OBJEXT for target clean + * support/regression/tests/vaargs.c: fixed gcc 3.3 warning + * support/regression/tests/zeropad.c: added + 2003-05-09 * src/SDCCglue.c: fixed bug #597940 @@ -32,7 +42,7 @@ 2003-04-29 Kevin Vigor - Initial support for DS80C400. "Hello world" runs on TINIm400 + Initial support for DS80C400. "Hello world" runs on TINIm400 (with polled I/O). 2003-04-28 Karl Bongers(apply patches for Martin Helmling) diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 033b5afb..8b577228 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -49,7 +49,6 @@ char *fullSrcFileName; /* full name for the source file; */ /* can be NULL while c1mode or linking without compiling */ char *fullDstFileName; /* full name for the output file; */ /* only given by -o, otherwise NULL */ -size_t fullDstFileNameLen; /* size of previous string. */ char *dstFileName; /* destination file name without extension */ char *dstPath = ""; /* path for the output files; */ /* "" is equivalent with cwd */ @@ -645,20 +644,20 @@ _setModel (int model, const char *sz) static char * getStringArg(const char *szStart, char **argv, int *pi, int argc) { - if (argv[*pi][strlen(szStart)]) + if (argv[*pi][strlen(szStart)]) { return &argv[*pi][strlen(szStart)]; } - else + else { ++(*pi); - if (*pi >= argc) + if (*pi >= argc) { werror (E_ARGUMENT_MISSING, szStart); /* Die here rather than checking for errors later. */ exit(-1); } - else + else { return argv[*pi]; } @@ -666,7 +665,7 @@ getStringArg(const char *szStart, char **argv, int *pi, int argc) } /** Gets the integer argument to this option using the same rules as - getStringArg. + getStringArg. */ static int getIntArg(const char *szStart, char **argv, int *pi, int argc) @@ -1063,7 +1062,6 @@ parseCmdLine (int argc, char **argv) else { fullDstFileName = Safe_strdup (buffer); - fullDstFileNameLen = strlen(fullDstFileName) + 1; /* get rid of the "."-extension */ @@ -1262,7 +1260,7 @@ parseCmdLine (int argc, char **argv) /* if debug option is set then open the cdbFile */ if (options.debug && fullSrcFileName) { - SNPRINTF (scratchFileName, sizeof(scratchFileName), + SNPRINTF (scratchFileName, sizeof(scratchFileName), "%s.adb", dstFileName); //JCF: Nov 30, 2002 if(debugFile->openFile(scratchFileName)) debugFile->writeModule(moduleName); @@ -1283,7 +1281,7 @@ linkEdit (char **envp) int i, system_ret; /* first we need to create the .lnk file */ - SNPRINTF (scratchFileName, sizeof(scratchFileName), + SNPRINTF (scratchFileName, sizeof(scratchFileName), "%s.lnk", dstFileName); if (!(lnkfile = fopen (scratchFileName, "w"))) { @@ -1404,7 +1402,7 @@ linkEdit (char **envp) "Add support for your FLAT24 target in %s @ line %d\n", __FILE__, __LINE__); exit(-1); - } + } } #endif @@ -1490,43 +1488,36 @@ linkEdit (char **envp) else { strncpyz (scratchFileName, relFiles[0], sizeof(scratchFileName)); - /* strip "rel" extension */ + /* strip ".rel" extension */ p = strrchr (scratchFileName, '.'); if (p) { - p++; - *p = 0; + *p = 0; } - } strncatz (scratchFileName, - options.out_fmt ? "S19" : "ihx", + options.out_fmt ? ".S19" : ".ihx", sizeof(scratchFileName)); rename (scratchFileName, fullDstFileName); - q = strrchr (fullDstFileName, '.'); - if (q) - { - /* point after the '.' of the extension */ - q++; - } - else + strncpyz (buffer, fullDstFileName, sizeof(buffer)); + q = strrchr (buffer, '.'); + if (!q) { /* no extension: append new extensions */ - /* Don't we want to append a period here ? */ - q = strlen (fullDstFileName) + fullDstFileName; + q = strlen (buffer) + buffer; } - - *p = 0; - strncatz (scratchFileName, "map", sizeof(scratchFileName)); + + *p = 0; + strncatz (scratchFileName, ".map", sizeof(scratchFileName)); *q = 0; - strncatz(fullDstFileName, "map", fullDstFileNameLen); - rename (scratchFileName, fullDstFileName); - *p = 0; - strncatz (scratchFileName, "mem", sizeof(scratchFileName)); + strncatz(buffer, ".map", sizeof(buffer)); + rename (scratchFileName, buffer); + *p = 0; + strncatz (scratchFileName, ".mem", sizeof(scratchFileName)); *q = 0; - strncatz(fullDstFileName, "mem", fullDstFileNameLen); - rename (scratchFileName, fullDstFileName); + strncatz(buffer, ".mem", sizeof(buffer)); + rename (scratchFileName, buffer); } if (system_ret) { diff --git a/support/regression/Makefile b/support/regression/Makefile index 801d4681..1f29aa25 100644 --- a/support/regression/Makefile +++ b/support/regression/Makefile @@ -69,39 +69,39 @@ all: test-ports # Test all of the ports test-ports: - for i in $(ALL_PORTS); do $(MAKE) inter-port-clean test-port PORT=$$i; done + for i in $(ALL_PORTS); do $(MAKE) test-port PORT=$$i; done # Helper rule for testing the z80 port only test-z80: - $(MAKE) inter-port-clean test-port PORT=z80 + $(MAKE) test-port PORT=z80 # Helper rule for testing the z80 port only test-gbz80: - $(MAKE) inter-port-clean test-port PORT=gbz80 + $(MAKE) test-port PORT=gbz80 # Helper rule for testing the mcs51 port only test-mcs51: - $(MAKE) inter-port-clean test-port PORT=mcs51 + $(MAKE) test-port PORT=mcs51 test-mcs51-large: - $(MAKE) inter-port-clean test-port PORT=mcs51-large + $(MAKE) test-port PORT=mcs51-large test-mcs51-stack-auto: - $(MAKE) inter-port-clean make-library test-port PORT=mcs51-stack-auto + $(MAKE) make-library test-port PORT=mcs51-stack-auto # Helper rule for testing the ds390 port only test-ds390: - $(MAKE) inter-port-clean test-port PORT=ds390 + $(MAKE) test-port PORT=ds390 # Helper rule for testing the z80 port only(use ucSim simulator) test-ucz80: - $(MAKE) inter-port-clean test-port PORT=ucz80 + $(MAKE) test-port PORT=ucz80 # Helper rule for testing the xa51 port only(use ucSim simulator) test-xa51: - $(MAKE) inter-port-clean test-port PORT=xa51 + $(MAKE) test-port PORT=xa51 ### Helper rule for testing the host cc only test-host: - $(MAKE) inter-port-clean test-port PORT=host + $(MAKE) test-port PORT=host test-host2: $(MAKE) test-port PORT=host @@ -146,6 +146,7 @@ SDCCFLAGS += -Ifwk/include -Itests # Rule to generate the iterations of a test suite off the soure suite. $(PORT_CASES_DIR)/%/iterations.stamp: $(TESTS_DIR)/%.c $(GENERATE_CASES) echo Processing $< + rm -rf `dirname $@` mkdir -p `dirname $@` python $(GENERATE_CASES) $< `dirname $@` > /dev/null touch $@ @@ -194,10 +195,6 @@ $(RESULTS): $(SUB_RESULTS) # BeginGeneric rules -clean: inter-port-clean +clean: rm -rf $(CASES_DIR) $(RESULTS_DIR) *.pyc fwk/lib/timeout fwk/lib/timeout.exe for i in $(CLEAN_PORTS); do $(MAKE) -f $(PORTS_DIR)/$$i/spec.mk _clean PORTS_DIR=$(PORTS_DIR) PORT=$$i; done - -inter-port-clean: - rm -f fwk/lib/*.o fwk/lib/*.asm fwk/lib/*.rst fwk/lib/*.lst fwk/lib/*.rel \ - fwk/lib/*.ihx fwk/lib/*.map fwk/lib/*.sym diff --git a/support/regression/ports/host/spec.mk b/support/regression/ports/host/spec.mk index ce2c4a55..103dedce 100644 --- a/support/regression/ports/host/spec.mk +++ b/support/regression/ports/host/spec.mk @@ -3,6 +3,7 @@ SDCC = $(shell ( sh -c "gcc --version" 2>&1 ) > /dev/null && echo gcc || echo c SDCCFLAGS = -DPORT_HOST=1 -Wall -fsigned-char -DREENTRANT= EXEEXT = .bin +OBJEXT = .o # otherwise `make` deletes it and `make -j`will fail .PRECIOUS: ports/$(PORT)/testfwk$(OBJEXT) diff --git a/support/regression/tests/vaargs.c b/support/regression/tests/vaargs.c index 0b9ef4e9..49beb2f5 100644 --- a/support/regression/tests/vaargs.c +++ b/support/regression/tests/vaargs.c @@ -1,13 +1,20 @@ /** Tests argument passing to functions via va_args. Assumes that up to the first two arguments can be passed in registers. - type1: char, int - type2: char, int - type3: char, int + type1: va_char, int + type2: va_char, int + type3: va_char, int */ #include #include +/* gcc 3.3 throws a warning, if char is in '...' */ +#if defined(PORT_HOST) +# define va_char int +#else +# define va_char char +#endif + static {type1} returnFirstArg(int marker, ...) { diff --git a/support/regression/tests/zeropad.c b/support/regression/tests/zeropad.c new file mode 100644 index 00000000..a2d9004d --- /dev/null +++ b/support/regression/tests/zeropad.c @@ -0,0 +1,35 @@ +/** Zeropad tests. + + storage: idata, xdata, code, +*/ +#include + +#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) +# define data +# define idata +# define xdata +# define code +#endif + +struct x { + short a; + char b[10]; +}; + +struct x {storage} teststruct[3] = { + { 10, { 1, 2, 3, 4, 5} }, + { 20, { 11 } }, + { 30, { 6, 7, 8} } +}; + +void +testZeropad(void) +{ + ASSERT(teststruct[0].b[5] == 0); + ASSERT(teststruct[1].b[0] == 11); + + ASSERT(sizeof(teststruct[2].a) == 2); + ASSERT(sizeof(teststruct[1].b) == 10); + ASSERT(sizeof(teststruct[1]) == 12); + ASSERT(sizeof(teststruct) == 36); +} -- 2.30.2