core/smn_core.cpp
changeset 1333 cfb44989c53d
parent 1330 ab94316bb52b
child 1334 9db842b7a9fe
     1.1 --- a/core/smn_core.cpp	Wed Aug 15 08:08:42 2007 +0000
     1.2 +++ b/core/smn_core.cpp	Wed Aug 15 16:17:54 2007 +0000
     1.3 @@ -31,6 +31,7 @@
     1.4  
     1.5  #include <time.h>
     1.6  #include <string.h>
     1.7 +#include <stdlib.h>
     1.8  #include "sm_stringutil.h"
     1.9  #include "sm_globals.h"
    1.10  #include "sourcemod.h"
    1.11 @@ -100,14 +101,43 @@
    1.12  	return static_cast<cell_t>(t);
    1.13  }
    1.14  
    1.15 +#if defined SUBPLATFORM_SECURECRT
    1.16 +void _ignore_invalid_parameter(
    1.17 +						const wchar_t * expression,
    1.18 +						const wchar_t * function, 
    1.19 +						const wchar_t * file, 
    1.20 +						unsigned int line,
    1.21 +						uintptr_t pReserved
    1.22 +						)
    1.23 +{
    1.24 +	/* Wow we don't care, thanks Microsoft. */
    1.25 +}
    1.26 +#endif
    1.27 +
    1.28 +#include "sm_srvcmds.h"
    1.29 +
    1.30  static cell_t FormatTime(IPluginContext *pContext, const cell_t *params)
    1.31  {
    1.32  	char *format, *buffer;
    1.33  	pContext->LocalToString(params[1], &buffer);
    1.34  	pContext->LocalToString(params[3], &format);
    1.35  
    1.36 +#if defined SUBPLATFORM_SECURECRT
    1.37 +	_invalid_parameter_handler handler = _set_invalid_parameter_handler(_ignore_invalid_parameter);
    1.38 +#endif
    1.39 +
    1.40  	time_t t = (params[4] == -1) ? time(NULL) : (time_t)params[4];
    1.41 -	strftime(buffer, params[2], format, localtime(&t));
    1.42 +	size_t written = strftime(buffer, params[2], format, localtime(&t));
    1.43 +
    1.44 +#if defined SUBPLATFORM_SECURECRT
    1.45 +	_set_invalid_parameter_handler(handler);
    1.46 +#endif
    1.47 +
    1.48 +	if (params[2] && format[0] != '\0' && !written)
    1.49 +	{
    1.50 +		pContext->ThrowNativeError("Invalid time format or buffer too small");
    1.51 +		return 0;
    1.52 +	}
    1.53  
    1.54  	return 1;
    1.55  }