/*
- Copyright (C) 1999-2007 id Software, Inc. and contributors.
+ Copyright (C) 1999-2006 Id Software, Inc. and contributors.
For a list of contributors, see the accompanying CONTRIBUTORS file.
This file is part of GtkRadiant.
Safe strncpy that ensures a trailing zero
=============
*/
-void Q_strncpyz( char *dest, const char *src, int destsize ) {
+void Q_strncpyz( char *dest, const char *src, std::size_t destsize ) {
if ( !src ) {
Com_Error( ERR_FATAL, "Q_strncpyz: NULL src" );
}
// never goes past bounds or leaves without a terminating 0
-void Q_strcat( char *dest, int size, const char *src ) {
- int l1;
-
- l1 = strlen( dest );
+void Q_strcat( char *dest, std::size_t size, const char *src ) {
+ auto l1 = strlen( dest );
if ( l1 >= size ) {
Com_Error( ERR_FATAL, "Q_strcat: already overflowed" );
}
}
-void QDECL Com_sprintf( char *dest, int size, const char *fmt, ... ) {
- int len;
+void QDECL Com_sprintf( char *dest, std::size_t size, const char *fmt, ... ) {
va_list argptr;
char bigbuffer[32000]; // big, but small enough to fit in PPC stack
va_start( argptr,fmt );
- len = vsprintf( bigbuffer,fmt,argptr );
+ int ret = vsprintf( bigbuffer,fmt,argptr );
va_end( argptr );
+ if ( ret < 0 ) {
+ Com_Error(ERR_FATAL, "Com_sprintf: vsprintf failed");
+ }
+ auto len = static_cast<size_t>(ret);
if ( len >= sizeof( bigbuffer ) ) {
Com_Error( ERR_FATAL, "Com_sprintf: overflowed bigbuffer" );
}
FIXME: make this buffer size safe someday
============
*/
-char * QDECL va( char *format, ... ) {
+char *QDECL va( const char *format, ... ) {
va_list argptr;
static char string[2][32000]; // in case va is called by nested functions
static int index = 0;
FIXME: overflow check?
===============
*/
-char *Info_ValueForKey( const char *s, const char *key ) {
+const char *Info_ValueForKey( const char *s, const char *key ) {
char pkey[MAX_INFO_KEY];
static char value[2][MAX_INFO_VALUE]; // use two buffers so compares
// work without stomping on each other