Skip to content

Commit 95c6342

Browse files
committed
Remove hardcoded vres and fix CG_STRNCPY.
This is anternative approach compared to PR 104 by jackharrhy
1 parent af8c57b commit 95c6342

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

code/client/cl_cgame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) {
618618
Com_Memcpy( VMA(1), VMA(2), args[3] );
619619
return 0;
620620
case CG_STRNCPY:
621-
strncpy( VMA(1), VMA(2), args[3] );
621+
Q_strncpy( VMA(1), VMA(2), args[3] );
622622
return args[1];
623623
case CG_SIN:
624624
return FloatAsInt( sin( VMF(1) ) );

code/qcommon/q_shared.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,25 @@ int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
789789
}
790790
#endif
791791

792+
/*
793+
Copied from code/game/bg_lib.c
794+
It is here to avoid undifined behavior when source and destination overlap.
795+
This is used quite a lot in the code.
796+
*/
797+
char *Q_strncpy(char *strDest, const char *strSource, size_t count) {
798+
char *s;
799+
800+
s = strDest;
801+
while (*strSource && count) {
802+
*s++ = *strSource++;
803+
count--;
804+
}
805+
while (count--) {
806+
*s++ = 0;
807+
}
808+
return strDest;
809+
}
810+
792811
/*
793812
=============
794813
Q_strncpyz
@@ -807,7 +826,7 @@ void Q_strncpyz( char *dest, const char *src, int destsize ) {
807826
Com_Error(ERR_FATAL,"Q_strncpyz: destsize < 1" );
808827
}
809828

810-
strncpy( dest, src, destsize-1 );
829+
Q_strncpy( dest, src, destsize-1 );
811830
dest[destsize-1] = 0;
812831
}
813832

code/qcommon/q_shared.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ char *Q_strupr( char *s1 );
811811
const char *Q_stristr( const char *s, const char *find);
812812

813813
// buffer size safe library replacements
814+
char *Q_strncpy(char *strDest, const char *strSource, size_t count);
814815
void Q_strncpyz( char *dest, const char *src, int destsize );
815816
void Q_strcat( char *dest, int size, const char *src );
816817

code/sdl/sdl_glimp.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,6 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
630630
vresWidth = glConfig.vidWidth;
631631
vresHeight = glConfig.vidHeight;
632632

633-
634-
635-
636-
vresWidth = 640;
637-
vresHeight = 480;
638-
639633
#if SDL_MAJOR_VERSION != 2
640634
screen = vidscreen;
641635
#endif

0 commit comments

Comments
 (0)