Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1b46625

Browse files
committedDec 3, 2024·
Fix compilation and simplify Com_VPrintf
1 parent eb22da9 commit 1b46625

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed
 

‎src/qcommon/common.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ to the appropriate place.
198198
A raw string should NEVER be passed as fmt, because of "%f" type crashers.
199199
=============
200200
*/
201-
static qboolean devPrint = qfalse;
202-
int FORMAT_PRINTF(1, 0) QDECL Com_VPrintf( const char *fmt, va_list argptr ) {
201+
static int FORMAT_PRINTF(2, 0) QDECL Com_VPrintf( qboolean devPrint, const char *fmt, va_list argptr ) {
203202
static qboolean opening_qconsole = qfalse;
204203
char msg[MAXPRINTMSG];
205204
int len;
@@ -291,7 +290,7 @@ void FORMAT_PRINTF(1, 2) QDECL Com_Printf( const char *fmt, ... ) {
291290
va_list argptr;
292291

293292
va_start( argptr, fmt );
294-
Com_VPrintf( fmt, argptr );
293+
Com_VPrintf( qfalse, fmt, argptr );
295294
va_end( argptr );
296295
}
297296

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

313312
va_start( argptr, fmt );
314-
devPrint = qtrue;
315-
Com_VPrintf( fmt, argptr );
316-
devPrint = qfalse;
313+
Com_VPrintf( qtrue, fmt, argptr );
317314
va_end( argptr );
318315
}
319316

‎src/qcommon/q_shared.c

+38-5
Original file line numberDiff line numberDiff line change
@@ -1533,18 +1533,51 @@ void Q_strncpyz( char *dest, const char *src, int destsize )
15331533
/*
15341534
=============
15351535
Q_strncpy
1536+
1537+
allows src and dest to be overlapped for QVM compatibility purposes
15361538
=============
15371539
*/
1538-
char *Q_strncpy( char *dest, const char *src, int destsize )
1540+
char *Q_strncpy( char *dest, char *src, int destsize )
15391541
{
1540-
char *start = dest;
1542+
char *s = src, *start = dest;
1543+
int src_len;
15411544

1542-
while ( destsize > 0 && (*dest++ = *src++) != '\0' ) {
1543-
--destsize;
1545+
while ( *s != '\0' )
1546+
++s;
1547+
src_len = (int)(s - src);
1548+
1549+
if ( src_len > destsize ) {
1550+
src_len = destsize;
15441551
}
1552+
destsize -= src_len;
15451553

1546-
while ( --destsize > 0 ) {
1554+
if ( dest > src && dest < src + src_len ) {
1555+
int i;
1556+
#ifdef _DEBUG
1557+
Com_Printf( S_COLOR_YELLOW "Q_strncpy: overlapped (dest > src) buffers\n" );
1558+
#endif
1559+
for ( i = src_len - 1; i >= 0; --i ) {
1560+
dest[i] = src[i]; // back overlapping
1561+
}
1562+
dest += src_len;
1563+
} else {
1564+
#ifdef _DEBUG
1565+
if ( src >= dest && src < dest + src_len ) {
1566+
Com_Printf( S_COLOR_YELLOW "Q_strncpy: overlapped (src >= dst) buffers\n" );
1567+
#ifdef _MSC_VER
1568+
// __debugbreak();
1569+
#endif
1570+
}
1571+
#endif
1572+
while ( src_len > 0 ) {
1573+
*dest++ = *src++;
1574+
--src_len;
1575+
}
1576+
}
1577+
1578+
while ( destsize > 0 ) {
15471579
*dest++ = '\0';
1580+
--destsize;
15481581
}
15491582

15501583
return start;

‎src/qcommon/qcommon.h

-1
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,6 @@ void Info_Print( const char *s );
10971097

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

0 commit comments

Comments
 (0)
Please sign in to comment.