Changeset 3161

Show
Ignore:
Timestamp:
15/09/2007 23:59:14 (3 years ago)
Author:
NiLuJe
Message:

Sync MetaMod-P:

  • Remove of complex long log string fix, introduce simple fix
Location:
Mirrors/MetaMod-P/metamod/metamod
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • Mirrors/MetaMod-P/metamod/metamod/CVS/Entries

    r3061 r3161  
    7474/commands_meta.cpp/1.7/Mon Aug 13 00:44:16 2007// 
    7575/dllapi.cpp/1.15/Mon Aug 13 00:44:16 2007// 
    76 /engine_api.cpp/1.14/Mon Aug 13 00:44:16 2007// 
    7776/log_meta.cpp/1.8/Mon Aug 13 00:44:16 2007// 
    7877/log_meta.h/1.10/Mon Aug 13 00:44:16 2007// 
    7978/metamod.cpp/1.13/Mon Aug 13 00:44:17 2007// 
    8079/metamod.h/1.12/Mon Aug 13 00:44:17 2007// 
    81 /osdep.cpp/1.10/Mon Aug 13 00:44:20 2007// 
    82 /osdep.h/1.10/Mon Aug 13 00:44:20 2007// 
    8380/osdep_linkent_linux.cpp/1.10/Mon Aug 13 00:44:20 2007// 
    8481/vers_meta.h/1.20/Mon Aug 13 00:44:21 2007// 
     82/engine_api.cpp/1.15/Sat Sep 15 21:57:21 2007// 
     83/osdep.cpp/1.11/Sat Sep 15 21:57:21 2007// 
     84/osdep.h/1.11/Sat Sep 15 21:57:21 2007// 
    8585D 
  • Mirrors/MetaMod-P/metamod/metamod/engine_api.cpp

    r3061 r3161  
    6666 
    6767// For varargs functions 
    68 #ifndef DO_NOT_FIX_VARARG_ENGINE_API_WARPERS 
    69         #define MAKE_FORMATED_STRING(szFmt) \ 
    70                 char strbuf[MAX_STRBUF_LEN]; \ 
    71                 char * buf=strbuf; \ 
    72                 { \ 
    73                         int len; \ 
    74                         va_list vargs; \ 
    75                         va_start(vargs, szFmt); \ 
    76                         len = safe_vsnprintf(strbuf, sizeof(strbuf), szFmt, vargs); \ 
    77                         va_end(vargs); \ 
    78                         if((unsigned)len >= sizeof(strbuf)) { \ 
    79                                 buf = (char *)malloc(len + 1); \ 
    80                                 if(buf) { \ 
    81                                         va_start(vargs, szFmt); \ 
    82                                         safevoid_vsnprintf(buf, len + 1, szFmt, vargs); \ 
    83                                         va_end(vargs); \ 
    84                                 } else { \ 
    85                                         buf=strbuf; \ 
    86                                 } \ 
    87                         } \ 
    88                 } 
    89         #define CLEAN_FORMATED_STRING() \ 
    90                 if(buf != strbuf) \ 
    91                         free(buf); 
    92 #else 
    93         #define MAKE_FORMATED_STRING(szFmt) \ 
    94                 char buf[MAX_STRBUF_LEN]; \ 
    95                 va_list ap; \ 
    96                 va_start(ap, szFmt); \ 
    97                 safevoid_vsnprintf(buf, sizeof(buf), szFmt, ap); \ 
    98                 va_end(ap); 
    99          
    100         #define CLEAN_FORMATED_STRING() 
    101 #endif 
     68#define MAKE_FORMATED_STRING(szFmt) \ 
     69        char buf[MAX_STRBUF_LEN*4]; \ 
     70        va_list ap; \ 
     71        va_start(ap, szFmt); \ 
     72        safevoid_vsnprintf(buf, sizeof(buf), szFmt, ap); \ 
     73        va_end(ap); 
    10274 
    10375// Engine routines, printf-style functions returning "void". 
     
    10880        API_PACK_ARGS(pack_args_type, (pfn_arg, "%s", buf)); \ 
    10981        main_hook_function_void(offsetof(engine_info_t, pfnName), e_api_engine, offsetof(enginefuncs_t, pfnName), &packed_args); \ 
    110         API_END_TSC_TRACKING() \ 
    111         CLEAN_FORMATED_STRING() 
     82        API_END_TSC_TRACKING() 
    11283 
    11384// Engine routines, printf-style functions returning an actual value. 
     
    11889        API_PACK_ARGS(pack_args_type, (pfn_arg, "%s", buf)); \ 
    11990        class_ret_t ret_val(main_hook_function(class_ret_t((ret_t)ret_init), offsetof(engine_info_t, pfnName), e_api_engine, offsetof(enginefuncs_t, pfnName), &packed_args)); \ 
    120         API_END_TSC_TRACKING() \ 
    121         CLEAN_FORMATED_STRING() 
     91        API_END_TSC_TRACKING() 
    12292 
    12393 
  • Mirrors/MetaMod-P/metamod/metamod/osdep.cpp

    r3061 r3161  
    9292                *c = tolower(*c); 
    9393        return(s); 
    94 } 
    95 #endif 
    96  
    97  
    98 #ifndef DO_NOT_FIX_VARARG_ENGINE_API_WARPERS 
    99 // Microsoft's msvcrt.dll:vsnprintf is buggy and so is vsnprintf on some glibc versions. 
    100 // We use wrapper function to fix bugs. 
    101 //  from: http://sourceforge.net/tracker/index.php?func=detail&aid=1083721&group_id=2435&atid=102435 
    102 int DLLINTERNAL safe_vsnprintf(char* s, size_t n, const char *format, va_list src_ap) {  
    103         va_list ap; 
    104         int res; 
    105         char *tmpbuf; 
    106         size_t bufsize = n; 
    107          
    108         if(s && n>0) 
    109                 s[0]=0; 
    110          
    111         // If the format string is empty, nothing to do. 
    112         if(!format || !*format) 
    113                 return(0); 
    114          
    115         // The supplied count may be big enough. Try to use the library 
    116         // vsnprintf, fixing up the case where the library function 
    117         // neglects to terminate with '/0'. 
    118         if(n > 0) 
    119         { 
    120                 // A NULL destination will cause a segfault with vsnprintf. 
    121                 // if n > 0.  Nor do we want to copy our tmpbuf to NULL later. 
    122                 if(!s) 
    123                         return(-1); 
    124                  
    125                 va_copy(ap, src_ap); 
    126                 res = vsnprintf(s, n, format, ap); 
    127                 va_end(ap); 
    128                  
    129                 if(res > 0) { 
    130                         if((unsigned)res == n) 
    131                                 s[res - 1] = 0; 
    132                         return(res); 
    133                 } 
    134                  
    135                 // If n is already larger than INT_MAX, increasing it won't 
    136                 // help. 
    137                 if(n > INT_MAX) 
    138                         return(-1); 
    139                  
    140                 // Try a larger buffer. 
    141                 bufsize *= 2; 
    142         } 
    143          
    144         if(bufsize < 1024) 
    145                 bufsize = 1024; 
    146          
    147         tmpbuf = (char *)malloc(bufsize * sizeof(char)); 
    148         if(!tmpbuf) 
    149                 return(-1); 
    150          
    151         va_copy(ap, src_ap); 
    152         res = vsnprintf(tmpbuf, bufsize, format, ap); 
    153         va_end(ap); 
    154          
    155         // The test for bufsize limit is probably not necesary 
    156         // with 2GB address space limit, since, in practice, malloc will 
    157         // fail well before INT_MAX. 
    158         while(res < 0 && bufsize <= INT_MAX) { 
    159                 char * newbuf; 
    160                  
    161                 bufsize *= 2; 
    162                 newbuf = (char*)realloc(tmpbuf, bufsize * sizeof(char)); 
    163                  
    164                 if(!newbuf) 
    165                         break; 
    166                  
    167                 tmpbuf = newbuf; 
    168                  
    169                 va_copy(ap, src_ap); 
    170                 res = vsnprintf(tmpbuf, bufsize, format, ap); 
    171                 va_end(ap); 
    172         } 
    173          
    174         if(res > 0 && n > 0) { 
    175                 if(n > (unsigned)res) 
    176                         memcpy(s, tmpbuf, (res + 1) * sizeof (char)); 
    177                 else { 
    178                         memcpy(s, tmpbuf, (n - 1) * sizeof (char)); 
    179                         s[n - 1] = 0; 
    180                 } 
    181         } 
    182          
    183         free(tmpbuf); 
    184         return(res); 
    185 } 
    186  
    187 int DLLINTERNAL safe_snprintf(char* s, size_t n, const char* format, ...) { 
    188         int res; 
    189         va_list ap; 
    190          
    191         va_start(ap, format); 
    192         res = safe_vsnprintf(s, n, format, ap); 
    193         va_end(ap); 
    194          
    195         return(res); 
    19694} 
    19795#endif 
     
    397295        return(mTRUE); 
    398296} 
    399  
  • Mirrors/MetaMod-P/metamod/metamod/osdep.h

    r3061 r3161  
    9999 
    100100// Special version that fixes vsnprintf bugs. 
    101 #ifndef DO_NOT_FIX_VARARG_ENGINE_API_WARPERS 
    102 int DLLINTERNAL safe_vsnprintf(char* s,  size_t n,  const char *format, va_list ap); 
    103 int DLLINTERNAL safe_snprintf(char* s, size_t n, const char* format, ...); 
    104 #endif 
    105101void DLLINTERNAL safevoid_vsnprintf(char* s, size_t n, const char *format, va_list ap); 
    106102void DLLINTERNAL safevoid_snprintf(char* s, size_t n, const char* format, ...);