diff --git a/src/sim65/main.c b/src/sim65/main.c index f2daf9295..d92d52ef6 100644 --- a/src/sim65/main.c +++ b/src/sim65/main.c @@ -36,6 +36,7 @@ #include #include #include +#include /* common */ #include "abend.h" @@ -63,6 +64,12 @@ const char* ProgramFile; /* exit simulator after MaxCycles Cycles */ unsigned long MaxCycles; +/* maximum number of cycles that can be tested, +** requires overhead for longest possible instruction, +** which should be 7, using 16 for safety. +*/ +#define MAXCYCLES_LIMIT (ULONG_MAX-16) + /* Header signature 'sim65' */ static const unsigned char HeaderSignature[] = { 0x73, 0x69, 0x6D, 0x36, 0x35 @@ -72,7 +79,6 @@ static const unsigned char HeaderSignature[] = { static const unsigned char HeaderVersion = 2; - /*****************************************************************************/ /* Code */ /*****************************************************************************/ @@ -140,6 +146,10 @@ static void OptQuitXIns (const char* Opt attribute ((unused)), /* quit after MaxCycles cycles */ { MaxCycles = strtoul(Arg, NULL, 0); + /* Guard against overflow. */ + if (MaxCycles >= MAXCYCLES_LIMIT) { + Error("'-x parameter out of range. Max: %lu",MAXCYCLES_LIMIT); + } } static unsigned char ReadProgramFile (void) @@ -184,6 +194,7 @@ static unsigned char ReadProgramFile (void) } /* Get load address */ + Val2 = 0; /* suppress uninitialized variable warning */ if (((Val = fgetc(F)) == EOF) || ((Val2 = fgetc(F)) == EOF)) { Error ("'%s': Header missing load address", ProgramFile); diff --git a/src/sim65/paravirt.c b/src/sim65/paravirt.c index 9e5c28432..0b16f89e9 100644 --- a/src/sim65/paravirt.c +++ b/src/sim65/paravirt.c @@ -242,7 +242,15 @@ static void PVClose (CPURegs* Regs) Print (stderr, 2, "PVClose ($%04X)\n", FD); - RetVal = close (FD); + if (FD != 0xFFFF) { + RetVal = close (FD); + } else { + /* test/val/constexpr.c "abuses" close, expecting close(-1) to return -1. + ** This behaviour is not the same on all target platforms. + ** MSVC's close treats it as a fatal error instead and terminates. + */ + RetVal = 0xFFFF; + } SetAX (Regs, RetVal); } diff --git a/test/asm/val/Makefile b/test/asm/val/Makefile index 91dae9afd..09a6b91bc 100644 --- a/test/asm/val/Makefile +++ b/test/asm/val/Makefile @@ -22,7 +22,8 @@ ifdef QUIET NULLERR = 2>$(NULLDEV) endif -SIM65FLAGS = -x 5000000000 +# sim65 can support 64-bit cycle counts on some platforms, but not all. This must fit in 32-bit. +SIM65FLAGS = -x 4000000000 CA65 := $(if $(wildcard ../../../bin/ca65*),..$S..$S..$Sbin$Sca65,ca65) LD65 := $(if $(wildcard ../../../bin/ld65*),..$S..$S..$Sbin$Sld65,ld65) diff --git a/test/standard/Makefile b/test/standard/Makefile index 054623b79..40299c1bf 100644 --- a/test/standard/Makefile +++ b/test/standard/Makefile @@ -22,7 +22,8 @@ ifdef QUIET NULLERR = 2>$(NULLDEV) endif -SIM65FLAGS = -x 5000000000 -c +# sim65 can support 64-bit cycle counts on some platforms, but not all. This must fit in 32-bit. +SIM65FLAGS = -x 4000000000 -c CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65) diff --git a/test/val/Makefile b/test/val/Makefile index a3722f7bf..158967f9e 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -24,7 +24,8 @@ ifdef QUIET NULLERR = 2>$(NULLDEV) endif -SIM65FLAGS = -x 5000000000 -c +# sim65 can support 64-bit cycle counts on some platforms, but not all. This must fit in 32-bit. +SIM65FLAGS = -x 4000000000 -c CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65)