From 6a2db55fc2be1875027a196fdd4ba4daa90a3e7f Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Fri, 10 Sep 2004 07:41:13 +0000 Subject: [PATCH] - Added the test program for the sprintf() buffer flush bug, courtesy of Jens Langner. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14725 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- test_programs/GNUmakefile.68k | 10 +++++++--- test_programs/smakefile | 11 ++++++++--- test_programs/sprintf_test.c | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 test_programs/sprintf_test.c diff --git a/test_programs/GNUmakefile.68k b/test_programs/GNUmakefile.68k index 9b09a82..00e9922 100644 --- a/test_programs/GNUmakefile.68k +++ b/test_programs/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.1 2004-08-14 15:01:22 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.2 2004-09-10 07:41:13 obarthel Exp $ # # :ts=8 # @@ -46,10 +46,10 @@ LIBS = -lm -lc -lgcc ############################################################################## -all: test fgets_test iotest sscanf_test printf_test stack_size_test translate_test +all: test fgets_test iotest sscanf_test printf_test sprintf_test stack_size_test translate_test clean: - $(DELETE) #?.o #?.map test fgets_test iotest sscanf_test printf_test stack_size_test translate_test + $(DELETE) #?.o #?.map test fgets_test iotest sscanf_test printf_test sprintf_test stack_size_test translate_test ############################################################################## @@ -73,6 +73,10 @@ printf_test : printf_test.o @echo "Linking $@" $(CC) $(CFLAGS) -o $@ printf_test.o $(LIBS) -Wl,--cref,-M,-Map=$@.map +sprintf_test : sprintf_test.o + @echo "Linking $@" + $(CC) $(CFLAGS) -o $@ sprintf_test.o $(LIBS) -Wl,--cref,-M,-Map=$@.map + stack_size_test : stack_size_test.o @echo "Linking $@" $(CC) $(CFLAGS) -o $@ stack_size_test.o $(LIBS) -Wl,--cref,-M,-Map=$@.map diff --git a/test_programs/smakefile b/test_programs/smakefile index c458159..c5ea010 100644 --- a/test_programs/smakefile +++ b/test_programs/smakefile @@ -1,5 +1,5 @@ # -# $Id: smakefile,v 1.1 2004-08-06 11:51:50 obarthel Exp $ +# $Id: smakefile,v 1.2 2004-09-10 07:41:13 obarthel Exp $ # # :ts=8 # @@ -63,10 +63,10 @@ AFLAGS = \ ############################################################################## -all: setup test fgets_test iotest sscanf_test printf_test stack_size_test translate_test cleanup +all: setup test fgets_test iotest sscanf_test printf_test sprintf_test stack_size_test translate_test cleanup clean: - -delete \#?.o \#?.map test fgets_test iotest sscanf_test printf_test stack_size_test translate_test + -delete \#?.o \#?.map test fgets_test iotest sscanf_test printf_test sprintf_test stack_size_test translate_test ############################################################################## @@ -105,6 +105,11 @@ printf_test: printf_test.o @slink $(LIB)startup.o printf_test.o to $@ lib $(LIB)c.lib addsym \ map $@.map,fhx fwidth 32 pwidth 32 swidth 32 +sprintf_test: sprintf_test.o + @echo "Linking $@" + @slink $(LIB)startup.o sprintf_test.o to $@ lib $(LIB)c.lib addsym \ + map $@.map,fhx fwidth 32 pwidth 32 swidth 32 + stack_size_test: stack_size_test.o @echo "Linking $@" @slink $(LIB)startup.o stack_size_test.o to $@ lib $(LIB)c.lib addsym \ diff --git a/test_programs/sprintf_test.c b/test_programs/sprintf_test.c new file mode 100644 index 0000000..40e92a1 --- /dev/null +++ b/test_programs/sprintf_test.c @@ -0,0 +1,25 @@ +#include +#include + +static char buf[256]; + +void addsomething(void) +{ + char *p = &buf[strlen(buf)]; + sprintf(p, "yeah"); +} + +int main(void) +{ + buf[0] = '\0'; + + addsomething(); + printf("1: [%s]\n", buf); + + sprintf(buf, ""); + + addsomething(); + printf("2: [%s]\n", buf); + + return (0); +}