Skip to content

Commit

Permalink
Fix compilation and simplify Com_VPrintf
Browse files Browse the repository at this point in the history
  • Loading branch information
ensiform committed Dec 3, 2024
1 parent eb22da9 commit 1b46625
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/qcommon/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ to the appropriate place.
A raw string should NEVER be passed as fmt, because of "%f" type crashers.
=============
*/
static qboolean devPrint = qfalse;
int FORMAT_PRINTF(1, 0) QDECL Com_VPrintf( const char *fmt, va_list argptr ) {
static int FORMAT_PRINTF(2, 0) QDECL Com_VPrintf( qboolean devPrint, const char *fmt, va_list argptr ) {
static qboolean opening_qconsole = qfalse;
char msg[MAXPRINTMSG];
int len;
Expand Down Expand Up @@ -291,7 +290,7 @@ void FORMAT_PRINTF(1, 2) QDECL Com_Printf( const char *fmt, ... ) {
va_list argptr;

va_start( argptr, fmt );
Com_VPrintf( fmt, argptr );
Com_VPrintf( qfalse, fmt, argptr );
va_end( argptr );
}

Expand All @@ -311,9 +310,7 @@ void FORMAT_PRINTF(1, 2) QDECL Com_DPrintf( const char *fmt, ...) {
}

va_start( argptr, fmt );
devPrint = qtrue;
Com_VPrintf( fmt, argptr );
devPrint = qfalse;
Com_VPrintf( qtrue, fmt, argptr );
va_end( argptr );
}

Expand Down
43 changes: 38 additions & 5 deletions src/qcommon/q_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -1533,18 +1533,51 @@ void Q_strncpyz( char *dest, const char *src, int destsize )
/*
=============
Q_strncpy
allows src and dest to be overlapped for QVM compatibility purposes
=============
*/
char *Q_strncpy( char *dest, const char *src, int destsize )
char *Q_strncpy( char *dest, char *src, int destsize )
{
char *start = dest;
char *s = src, *start = dest;
int src_len;

while ( destsize > 0 && (*dest++ = *src++) != '\0' ) {
--destsize;
while ( *s != '\0' )
++s;
src_len = (int)(s - src);

if ( src_len > destsize ) {
src_len = destsize;
}
destsize -= src_len;

while ( --destsize > 0 ) {
if ( dest > src && dest < src + src_len ) {
int i;
#ifdef _DEBUG
Com_Printf( S_COLOR_YELLOW "Q_strncpy: overlapped (dest > src) buffers\n" );
#endif
for ( i = src_len - 1; i >= 0; --i ) {
dest[i] = src[i]; // back overlapping
}
dest += src_len;
} else {
#ifdef _DEBUG
if ( src >= dest && src < dest + src_len ) {
Com_Printf( S_COLOR_YELLOW "Q_strncpy: overlapped (src >= dst) buffers\n" );
#ifdef _MSC_VER
// __debugbreak();
#endif
}
#endif
while ( src_len > 0 ) {
*dest++ = *src++;
--src_len;
}
}

while ( destsize > 0 ) {
*dest++ = '\0';
--destsize;
}

return start;
Expand Down
1 change: 0 additions & 1 deletion src/qcommon/qcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,6 @@ void Info_Print( const char *s );

void Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(const char *));
void Com_EndRedirect( void );
int QDECL Com_VPrintf( const char *fmt, va_list argptr ) FORMAT_PRINTF(1, 0); // conforms to vprintf prototype for print callback passing
void QDECL Com_Printf( const char *fmt, ... ) FORMAT_PRINTF(1, 2);
void QDECL Com_DPrintf( const char *fmt, ... ) FORMAT_PRINTF(1, 2);
void NORETURN QDECL Com_Error( errorParm_t code, const char *fmt, ... ) FORMAT_PRINTF(2, 3);
Expand Down

0 comments on commit 1b46625

Please sign in to comment.