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
This commit is contained in:
Michael "Code Poet" Pohoreski 2023-04-24 20:00:08 -07:00 committed by GitHub
parent a140946a23
commit f8da683d45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 18 deletions

View File

@ -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

View File

@ -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++;

View File

@ -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 ;

View File

@ -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 );
}