From 4c2463d1a124218f43a9eb10183300a04e3f7ae8 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Thu, 8 Aug 2013 21:29:30 -0700 Subject: [PATCH] Fix Bug 2021: Win32: Stack overflow due to recursive SDL_LogOutput on SDL_LogError without console; fix off-by-one error in SDLtest test suite --- src/SDL_log.c | 11 ++++++----- test/testautomation_sdltest.c | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/SDL_log.c b/src/SDL_log.c index c48f9ab8f..2245946c6 100644 --- a/src/SDL_log.c +++ b/src/SDL_log.c @@ -317,6 +317,7 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, { #if defined(__WIN32__) /* Way too many allocations here, urgh */ + /* Note: One can't call SDL_SetError here, since that function itself logs. */ { char *output; size_t length; @@ -331,16 +332,16 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, if (!attachResult) { attachError = GetLastError(); if (attachError == ERROR_INVALID_HANDLE) { - SDL_SetError("Parent process has no console"); + OutputDebugString(TEXT("Parent process has no console")); consoleAttached = -1; } else if (attachError == ERROR_GEN_FAILURE) { - SDL_SetError("Could not attach to console of parent process"); + OutputDebugString(TEXT("Could not attach to console of parent process")); consoleAttached = -1; } else if (attachError == ERROR_ACCESS_DENIED) { /* Already attached */ consoleAttached = 1; } else { - SDL_SetError("Error %d attaching console", attachError); + OutputDebugString(TEXT("Error attaching console")); consoleAttached = -1; } } else { @@ -364,10 +365,10 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, /* Screen output to stderr, if console was attached. */ if (consoleAttached == 1) { if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) { - SDL_SetError("Error %d calling WriteConsole", GetLastError()); + OutputDebugString(TEXT("Error calling WriteConsole")); } if (charsWritten == ERROR_NOT_ENOUGH_MEMORY) { - SDL_SetError("Insufficient heap memory to write message of size %d", length); + OutputDebugString(TEXT("Insufficient heap memory to write message")); } } diff --git a/test/testautomation_sdltest.c b/test/testautomation_sdltest.c index b8bc326a7..e0d921b49 100644 --- a/test/testautomation_sdltest.c +++ b/test/testautomation_sdltest.c @@ -63,7 +63,7 @@ sdltest_randomNumber(void *arg) SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result); result = (Sint64)SDLTest_RandomSint8(); - min = 1 - (1 << 7); + min = 0 - (1 << 7); max = (1 << 7) - 1; SDLTest_AssertPass("Call to SDLTest_RandomSint8"); SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result); @@ -74,7 +74,7 @@ sdltest_randomNumber(void *arg) SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result); result = (Sint64)SDLTest_RandomSint16(); - min = 1 - (1 << 15); + min = 0 - (1 << 15); max = (1 << 15) - 1; SDLTest_AssertPass("Call to SDLTest_RandomSint16"); SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result); @@ -85,7 +85,7 @@ sdltest_randomNumber(void *arg) SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result); result = (Sint64)SDLTest_RandomSint32(); - min = 1 - ((Sint64)1 << 31); + min = 0 - ((Sint64)1 << 31); max = ((Sint64)1 << 31) - 1; SDLTest_AssertPass("Call to SDLTest_RandomSint32"); SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);