]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/splines/q_shared.cpp
[q3map2] Unwind script stack in case of script loading error.
[xonotic/netradiant.git] / libs / splines / q_shared.cpp
index 033a6ee3120d4e725a727c498e5c08bc452b1cdd..1df4dfcd2c5de67676a444b0ddd2c2b9528f0d84 100644 (file)
@@ -546,7 +546,7 @@ char* Q_strrchr( const char* string, int c ){
    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" );
        }
@@ -633,10 +633,8 @@ char *Q_strupr( char *s1 ) {
 
 
 // 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" );
        }
@@ -689,14 +687,17 @@ char *Q_CleanStr( char *string ) {
 }
 
 
-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" );
        }
@@ -716,7 +717,7 @@ void QDECL Com_sprintf( char *dest, int size, const char *fmt, ... ) {
    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;
@@ -750,7 +751,7 @@ char    * QDECL va( char *format, ... ) {
    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