mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-09 09:41:12 +00:00
Check for empty string before printing in console
This commit is contained in:
parent
64df782287
commit
455ffec1e4
2 changed files with 23 additions and 4 deletions
|
@ -1035,6 +1035,9 @@ void I_OutputMsg(const char *fmt, ...)
|
||||||
va_start(argptr,fmt);
|
va_start(argptr,fmt);
|
||||||
len = vsnprintf(NULL, 0, fmt, argptr);
|
len = vsnprintf(NULL, 0, fmt, argptr);
|
||||||
va_end(argptr);
|
va_end(argptr);
|
||||||
|
if (len == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
txt = malloc(len+1);
|
txt = malloc(len+1);
|
||||||
va_start(argptr,fmt);
|
va_start(argptr,fmt);
|
||||||
vsprintf(txt, fmt, argptr);
|
vsprintf(txt, fmt, argptr);
|
||||||
|
@ -1134,7 +1137,7 @@ void I_OutputMsg(const char *fmt, ...)
|
||||||
if (!framebuffer)
|
if (!framebuffer)
|
||||||
fprintf(stderr, "%s", txt);
|
fprintf(stderr, "%s", txt);
|
||||||
#ifdef HAVE_TERMIOS
|
#ifdef HAVE_TERMIOS
|
||||||
if (consolevent && txt[strlen(txt)-1] == '\n')
|
if (consolevent && txt[len-1] == '\n')
|
||||||
{
|
{
|
||||||
write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor);
|
write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor);
|
||||||
ttycon_ateol = true;
|
ttycon_ateol = true;
|
||||||
|
|
|
@ -840,9 +840,16 @@ static void I_RegisterChildSignals(void)
|
||||||
void I_OutputMsg(const char *fmt, ...)
|
void I_OutputMsg(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char txt[8192];
|
char *txt;
|
||||||
va_list argptr;
|
va_list argptr;
|
||||||
|
|
||||||
|
va_start(argptr,fmt);
|
||||||
|
len = vsnprintf(NULL, 0, fmt, argptr);
|
||||||
|
va_end(argptr);
|
||||||
|
if (len == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
txt = malloc(len+1);
|
||||||
va_start(argptr,fmt);
|
va_start(argptr,fmt);
|
||||||
vsprintf(txt, fmt, argptr);
|
vsprintf(txt, fmt, argptr);
|
||||||
va_end(argptr);
|
va_end(argptr);
|
||||||
|
@ -876,7 +883,10 @@ void I_OutputMsg(const char *fmt, ...)
|
||||||
DWORD bytesWritten;
|
DWORD bytesWritten;
|
||||||
|
|
||||||
if (co == INVALID_HANDLE_VALUE)
|
if (co == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
free(txt);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (GetFileType(co) == FILE_TYPE_CHAR && GetConsoleMode(co, &bytesWritten))
|
if (GetFileType(co) == FILE_TYPE_CHAR && GetConsoleMode(co, &bytesWritten))
|
||||||
{
|
{
|
||||||
|
@ -892,11 +902,16 @@ void I_OutputMsg(const char *fmt, ...)
|
||||||
if (oldLength > 0)
|
if (oldLength > 0)
|
||||||
{
|
{
|
||||||
LPVOID blank = malloc(oldLength);
|
LPVOID blank = malloc(oldLength);
|
||||||
if (!blank) return;
|
if (!blank)
|
||||||
|
{
|
||||||
|
free(txt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
memset(blank, ' ', oldLength); // Blank out.
|
memset(blank, ' ', oldLength); // Blank out.
|
||||||
oldLines = malloc(oldLength*sizeof(TCHAR));
|
oldLines = malloc(oldLength*sizeof(TCHAR));
|
||||||
if (!oldLines)
|
if (!oldLines)
|
||||||
{
|
{
|
||||||
|
free(txt);
|
||||||
free(blank);
|
free(blank);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -941,7 +956,7 @@ void I_OutputMsg(const char *fmt, ...)
|
||||||
if (!framebuffer)
|
if (!framebuffer)
|
||||||
fprintf(stderr, "%s", txt);
|
fprintf(stderr, "%s", txt);
|
||||||
#ifdef HAVE_TERMIOS
|
#ifdef HAVE_TERMIOS
|
||||||
if (consolevent && txt[strlen(txt)-1] == '\n')
|
if (consolevent && txt[len-1] == '\n')
|
||||||
{
|
{
|
||||||
write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor);
|
write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor);
|
||||||
ttycon_ateol = true;
|
ttycon_ateol = true;
|
||||||
|
@ -953,6 +968,7 @@ void I_OutputMsg(const char *fmt, ...)
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
free(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue