From a140946a231d9013b8627c6b149d24bd1a15bc58 Mon Sep 17 00:00:00 2001 From: Andrea Date: Sun, 23 Apr 2023 21:10:51 +0200 Subject: [PATCH 1/2] RIFF: fix sizes. (PR #1214) --- source/Riff.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/Riff.cpp b/source/Riff.cpp index acb151ac..71aadc8a 100644 --- a/source/Riff.cpp +++ b/source/Riff.cpp @@ -32,7 +32,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA static HANDLE g_hRiffFile = INVALID_HANDLE_VALUE; static DWORD dwTotalOffset; static DWORD dwDataOffset; -static DWORD g_dwTotalNumberOfBytesWritten = 0; static unsigned int g_NumChannels = 2; bool RiffInitWriteFile(const char* pszFile, unsigned int sample_rate, unsigned int NumChannels) @@ -106,11 +105,13 @@ bool RiffFinishWriteFile() DWORD dwNumberOfBytesWritten; - temp32 = g_dwTotalNumberOfBytesWritten - (dwTotalOffset + 4); + DWORD fileSize = SetFilePointer(g_hRiffFile, 0, NULL, FILE_END); + + temp32 = fileSize - (dwTotalOffset + 4); SetFilePointer(g_hRiffFile, dwTotalOffset, NULL, FILE_BEGIN); WriteFile(g_hRiffFile, &temp32, 4, &dwNumberOfBytesWritten, NULL); - temp32 = g_dwTotalNumberOfBytesWritten - (dwDataOffset + 4); + temp32 = fileSize - (dwDataOffset + 4); SetFilePointer(g_hRiffFile, dwDataOffset, NULL, FILE_BEGIN); WriteFile(g_hRiffFile, &temp32, 4, &dwNumberOfBytesWritten, NULL); @@ -133,7 +134,5 @@ bool RiffPutSamples(const short* buf, unsigned int uSamples) &dwNumberOfBytesWritten, NULL); - g_dwTotalNumberOfBytesWritten += dwNumberOfBytesWritten; - return true; } From f8da683d4598c97a4784bc55a0ae450d1b0173ce Mon Sep 17 00:00:00 2001 From: "Michael \"Code Poet\" Pohoreski" Date: Mon, 24 Apr 2023 20:00:08 -0700 Subject: [PATCH 2/2] 1204 debugger long input crash (#1213) * Debugger: Clamp long input * Fix backspace when input line has 78 characters * Colorize console error line * Cleanup alignment * Init * Refactor common expression * Add support for a long input line when we decide to enable it * Unabbreviate SOL and EOL --- source/Debugger/Debug.cpp | 5 ++++- source/Debugger/Debugger_Console.cpp | 18 +++++++++------- source/Debugger/Debugger_Console.h | 11 +++++----- source/Debugger/Debugger_Display.cpp | 32 ++++++++++++++++++++++++---- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index fd27f938..154156c2 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -7154,6 +7154,9 @@ void WindowUpdateConsoleDisplayedSize () g_nConsoleDisplayWidth = CONSOLE_WIDTH - 1; g_bConsoleFullWidth = true; } + + g_nConsoleInputMaxLen = g_nConsoleDisplayWidth-1; // -1 prompt at Start-of-Line, -1 for cursor at End-of-Line + g_nConsoleInputScrollWidth = g_nConsoleDisplayWidth-1; // Maximum number of characters for the horizontol scrolling window on the input line #else g_nConsoleDisplayWidth = (CONSOLE_WIDTH / 2) + 10; g_bConsoleFullWidth = false; @@ -9040,7 +9043,7 @@ void DebuggerInputConsoleChar ( TCHAR ch ) return; } - if (g_nConsoleInputChars > (g_nConsoleDisplayWidth-1)) + if (g_nConsoleInputChars > g_nConsoleInputMaxLen) return; if ((ch >= CHAR_SPACE) && (ch <= 126)) // HACK MAGIC # 32 -> ' ', # 126 diff --git a/source/Debugger/Debugger_Console.cpp b/source/Debugger/Debugger_Console.cpp index a22932b5..7156bc93 100644 --- a/source/Debugger/Debugger_Console.cpp +++ b/source/Debugger/Debugger_Console.cpp @@ -80,11 +80,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA char g_aConsoleInput[ CONSOLE_WIDTH ]; // = g_aConsoleDisplay[0]; // Cooked input line (no prompt) - int g_nConsoleInputChars = 0; - char * g_pConsoleInput = 0; // points to past prompt - const char * g_pConsoleFirstArg = 0; // points to first arg - bool g_bConsoleInputQuoted = false; // Allows lower-case to be entered - char g_nConsoleInputSkip = '~'; + int g_nConsoleInputChars = 0; + char * g_pConsoleInput = 0; // points to past prompt + int g_nConsoleInputMaxLen = 0; + int g_nConsoleInputScrollWidth = 0; + const char * g_pConsoleFirstArg = 0; // points to first arg + bool g_bConsoleInputQuoted = false; // Allows lower-case to be entered + char g_nConsoleInputSkip = '~'; // Prototypes _______________________________________________________________ @@ -354,7 +356,7 @@ void ConsoleConvertFromText ( conchar_t * sText, const char * pText ) //=========================================================================== Update_t ConsoleDisplayError ( const char * pText ) { - ConsoleBufferPush( pText ); + ConsolePrintFormat( CHC_ERROR "%s", pText ); return ConsoleUpdate(); } @@ -430,7 +432,7 @@ bool ConsoleInputBackSpace () { if (g_nConsoleInputChars) { - g_pConsoleInput[ g_nConsoleInputChars ] = CHAR_SPACE; + g_pConsoleInput[ g_nConsoleInputChars ] = 0; g_nConsoleInputChars--; @@ -461,7 +463,7 @@ bool ConsoleInputClear () //=========================================================================== bool ConsoleInputChar ( char ch ) { - if (g_nConsoleInputChars < g_nConsoleDisplayWidth) // bug? include prompt? + if (g_nConsoleInputChars < g_nConsoleInputMaxLen) // GH #1204 Need to count the space at EOL for the cursor { g_pConsoleInput[ g_nConsoleInputChars ] = ch; g_nConsoleInputChars++; diff --git a/source/Debugger/Debugger_Console.h b/source/Debugger/Debugger_Console.h index 5fdd95ee..de629e18 100644 --- a/source/Debugger/Debugger_Console.h +++ b/source/Debugger/Debugger_Console.h @@ -245,11 +245,12 @@ extern char g_aConsoleInput[ CONSOLE_WIDTH ]; // Cooked input line (no prompt) - extern int g_nConsoleInputChars ; - extern char * g_pConsoleInput ; // points to past prompt - extern const char * g_pConsoleFirstArg ; // points to first arg - extern bool g_bConsoleInputQuoted ; - + extern int g_nConsoleInputChars ; + extern char * g_pConsoleInput ; // points to past prompt + extern int g_nConsoleInputMaxLen ; // = g_nConsoleDisplayWidth-1 = 78 // Maximum number of characters allowed on input line + extern int g_nConsoleInputScrollWidth; // = g_nConsoleDisplayWidth-1 = 78 // Maximum number of characters for the horizontol scrolling window on the input line + extern const char * g_pConsoleFirstArg ; // points to first arg + extern bool g_bConsoleInputQuoted ; extern char g_nConsoleInputSkip ; diff --git a/source/Debugger/Debugger_Display.cpp b/source/Debugger/Debugger_Display.cpp index 08eefc44..9682c552 100644 --- a/source/Debugger/Debugger_Display.cpp +++ b/source/Debugger/Debugger_Display.cpp @@ -1246,8 +1246,10 @@ void DrawConsoleCursor () int nLineHeight = GetConsoleLineHeightPixels(); int y = 0; + const int nInputWidth = min( g_nConsoleInputChars, g_nConsoleInputScrollWidth ); // NOTE: Keep in Sync! DrawConsoleInput() and DrawConsoleCursor() + RECT rect; - rect.left = (g_nConsoleInputChars + g_nConsolePromptLen) * nWidth; + rect.left = (nInputWidth + g_nConsolePromptLen) * nWidth; rect.top = GetConsoleTopPixels( y ); rect.bottom = rect.top + nLineHeight; //g_nFontHeight; rect.right = rect.left + nWidth; @@ -1295,9 +1297,31 @@ void DrawConsoleInput () RECT rect; GetConsoleRect( 0, rect ); - // Console background is drawn in DrawWindowBackground_Info -// DrawConsoleLine( g_aConsoleInput, 0 ); - PrintText( g_aConsoleInput, rect ); + // For long input only show last g_nConsoleInputScrollWidth characters + if (g_nConsoleInputChars > g_nConsoleInputScrollWidth) + { + assert(g_nConsoleInputScrollWidth <= CONSOLE_WIDTH); // NOTE: To support a wider input line the size of g_aConsoleInput[] must be increased + + // g_nConsoleInputMaxLen = 16; + // g_nConsoleInputScrollWidth = 10; + // + // 123456789ABCDEF g_aConsoleInput[] + // ^ g_nConsoleInputChars = 15 + // [--------] g_nConsoleInputScrollWidth = 10 + // >6789ABCDEF_ g_nConsoleInputMaxLen = 16 + static char aScrollingInput[ CONSOLE_WIDTH+1 ]; + aScrollingInput[0] = g_aConsoleInput[0]; // 1. Start-of-Line + + const int nInputOffset = g_nConsoleInputChars - g_nConsoleInputScrollWidth ; // 2. Middle + const int nInputWidth = min( g_nConsoleInputChars, g_nConsoleInputScrollWidth ); // NOTE: Keep in Sync! DrawConsoleInput() and DrawConsoleCursor() + strncpy( aScrollingInput+1, g_aConsoleInput + 1 + nInputOffset, nInputWidth ); // +1 to skip prompt + + aScrollingInput[ g_nConsoleInputScrollWidth+1 ] = 0; // 3. End-of-Line leave room for cursor + + PrintText( aScrollingInput, rect ); + } + else + PrintText( g_aConsoleInput, rect ); }