summaryrefslogtreecommitdiff
path: root/src/qcommon/q_shared.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/qcommon/q_shared.c')
-rw-r--r--src/qcommon/q_shared.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/qcommon/q_shared.c b/src/qcommon/q_shared.c
index f3220f1c..81248644 100644
--- a/src/qcommon/q_shared.c
+++ b/src/qcommon/q_shared.c
@@ -296,7 +296,7 @@ void COM_ParseError( char *format, ... )
static char string[4096];
va_start (argptr, format);
- vsprintf (string, format, argptr);
+ Q_vsnprintf (string, sizeof(string), format, argptr);
va_end (argptr);
Com_Printf("ERROR: %s, line %d: %s\n", com_parsename, com_lines, string);
@@ -308,7 +308,7 @@ void COM_ParseWarning( char *format, ... )
static char string[4096];
va_start (argptr, format);
- vsprintf (string, format, argptr);
+ Q_vsnprintf (string, sizeof(string), format, argptr);
va_end (argptr);
Com_Printf("WARNING: %s, line %d: %s\n", com_parsename, com_lines, string);
@@ -727,6 +727,28 @@ char* Q_strrchr( const char* string, int c )
return sp;
}
+qboolean Q_isanumber( const char *s )
+{
+#ifdef Q3_VM
+ //FIXME: implement
+ return qfalse;
+#else
+ char *p;
+
+ if( *s == '\0' )
+ return qfalse;
+
+ strtod( s, &p );
+
+ return *p == '\0';
+#endif
+}
+
+qboolean Q_isintegral( float f )
+{
+ return (int)f == f;
+}
+
/*
=============
Q_strncpyz
@@ -922,6 +944,18 @@ char *Q_CleanStr( char *string ) {
return string;
}
+int Q_CountChar(const char *string, char tocount)
+{
+ int count;
+
+ for(count = 0; *string; string++)
+ {
+ if(*string == tocount)
+ count++;
+ }
+
+ return count;
+}
void QDECL Com_sprintf( char *dest, int size, const char *fmt, ...) {
int len;
@@ -929,7 +963,7 @@ void QDECL Com_sprintf( char *dest, int size, const char *fmt, ...) {
char bigbuffer[32000]; // big, but small enough to fit in PPC stack
va_start (argptr,fmt);
- len = vsprintf (bigbuffer,fmt,argptr);
+ len = Q_vsnprintf (bigbuffer, sizeof(bigbuffer), fmt,argptr);
va_end (argptr);
if ( len >= sizeof( bigbuffer ) ) {
Com_Error( ERR_FATAL, "Com_sprintf: overflowed bigbuffer" );
@@ -952,20 +986,19 @@ va
does a varargs printf into a temp buffer, so I don't need to have
varargs versions of all text functions.
-FIXME: make this buffer size safe someday
============
*/
char * QDECL va( char *format, ... ) {
va_list argptr;
- static char string[2][32000]; // in case va is called by nested functions
- static int index = 0;
- char *buf;
+ static char string[2][32000]; // in case va is called by nested functions
+ static int index = 0;
+ char *buf;
buf = string[index & 1];
index++;
va_start (argptr, format);
- vsprintf (buf, format,argptr);
+ Q_vsnprintf (buf, sizeof(*string), format, argptr);
va_end (argptr);
return buf;
@@ -1145,7 +1178,8 @@ void Info_RemoveKey( char *s, const char *key ) {
if (!strcmp (key, pkey) )
{
- strcpy (start, s); // remove this part
+ memmove(start, s, strlen(s) + 1); // remove this part
+
return;
}