diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2016-12-23 14:41:28 +0100 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2016-12-23 05:41:28 -0800 |
commit | f5cbe4c9cab2873b60cd3c991732a250d2e164a2 (patch) | |
tree | 3dfef3ef56990e19fb914821ed4e6f36c9931fd1 /src/pal/inc | |
parent | 5ef3df8ffe059d5f91c6bae09d8f95a0332f1363 (diff) | |
download | coreclr-f5cbe4c9cab2873b60cd3c991732a250d2e164a2.tar.gz coreclr-f5cbe4c9cab2873b60cd3c991732a250d2e164a2.tar.bz2 coreclr-f5cbe4c9cab2873b60cd3c991732a250d2e164a2.zip |
Remove all usage of vsnprintf (#8709)
This change removes all usages of vsnprintf and modifies runtime to not to use
vsnprintf or _vsnprintf
I've also fixed two issues in PAL TRACE function string format parameters that
caused crashes when I was trying to run all PAL tests with PAL tracing enabled.
Diffstat (limited to 'src/pal/inc')
-rw-r--r-- | src/pal/inc/pal.h | 6 | ||||
-rw-r--r-- | src/pal/inc/rt/palrt.h | 30 | ||||
-rw-r--r-- | src/pal/inc/rt/safecrt.h | 4 |
3 files changed, 4 insertions, 36 deletions
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index 05c777c7ca..51ac5b9a5d 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -5640,7 +5640,6 @@ CoCreateGuid(OUT GUID * pguid); #define printf PAL_printf #define vprintf PAL_vprintf #define wprintf PAL_wprintf -#define swprintf PAL_swprintf #define wcsspn PAL_wcsspn #define wcstod PAL_wcstod #define wcstol PAL_wcstol @@ -5667,8 +5666,6 @@ CoCreateGuid(OUT GUID * pguid); #define iswxdigit PAL_iswxdigit #define towlower PAL_towlower #define towupper PAL_towupper -#define vsprintf PAL_vsprintf -#define vswprintf PAL_vswprintf #define realloc PAL_realloc #define fopen PAL_fopen #define strtok PAL_strtok @@ -5731,7 +5728,6 @@ CoCreateGuid(OUT GUID * pguid); #define _close PAL__close #define _wcstoui64 PAL__wcstoui64 #define _flushall PAL__flushall -#define _vsnprintf PAL__vsnprintf #define strnlen PAL_strnlen #ifdef _AMD64_ @@ -5809,7 +5805,6 @@ PALIMPORT char * __cdecl strstr(const char *, const char *); PALIMPORT char * __cdecl strtok(char *, const char *); PALIMPORT size_t __cdecl strspn(const char *, const char *); PALIMPORT size_t __cdecl strcspn(const char *, const char *); -PALIMPORT int __cdecl vsprintf(char *, const char *, va_list); PALIMPORT int __cdecl atoi(const char *); PALIMPORT LONG __cdecl atol(const char *); PALIMPORT ULONG __cdecl strtoul(const char *, char **, int); @@ -5873,7 +5868,6 @@ PALIMPORT WCHAR * __cdecl PAL_wcstok(WCHAR *, const WCHAR *); PALIMPORT size_t __cdecl PAL_wcscspn(const WCHAR *, const WCHAR *); PALIMPORT int __cdecl PAL_swprintf(WCHAR *, const WCHAR *, ...); PALIMPORT int __cdecl PAL_vswprintf(WCHAR *, const WCHAR *, va_list); -PALIMPORT int __cdecl PAL__vsnprintf(LPSTR Buffer, size_t Count, LPCSTR Format, va_list ap); PALIMPORT int __cdecl PAL_swscanf(const WCHAR *, const WCHAR *, ...); PALIMPORT LONG __cdecl PAL_wcstol(const WCHAR *, WCHAR **, int); PALIMPORT ULONG __cdecl PAL_wcstoul(const WCHAR *, WCHAR **, int); diff --git a/src/pal/inc/rt/palrt.h b/src/pal/inc/rt/palrt.h index c181f38c2b..ce637bad0e 100644 --- a/src/pal/inc/rt/palrt.h +++ b/src/pal/inc/rt/palrt.h @@ -893,7 +893,6 @@ Remember to fix the errcode defintion in safecrt.h. */ #define _wcslwr_s _wcslwr_unsafe -#define _snprintf_s _snprintf_unsafe #define swscanf_s swscanf #define _wfopen_s _wfopen_unsafe @@ -903,8 +902,6 @@ Remember to fix the errcode defintion in safecrt.h. #define _vscprintf _vscprintf_unsafe -#define vsprintf_s _vsnprintf - extern "C++" { #include <safemath.h> @@ -959,8 +956,11 @@ inline int __cdecl _vscprintf_unsafe(const char *_Format, va_list _ArgList) if(buf == nullptr) return 0; - int ret = _vsnprintf(buf, guess, _Format, _ArgList); + va_list argListCopy; + va_copy(argListCopy, _ArgList); + int ret = _vsnprintf_s(buf, guess, _TRUNCATE, _Format, argListCopy); free(buf); + va_end(argListCopy); if ((ret != -1) && (ret < guess)) return ret; @@ -969,28 +969,6 @@ inline int __cdecl _vscprintf_unsafe(const char *_Format, va_list _ArgList) } } -inline int __cdecl _vsnprintf_unsafe(char *_Dst, size_t _SizeInWords, size_t _Count, const char *_Format, va_list _ArgList) -{ - if (_Count == _TRUNCATE) _Count = _SizeInWords - 1; - int ret = _vsnprintf(_Dst, _Count, _Format, _ArgList); - _Dst[_SizeInWords - 1] = L'\0'; - if (ret < 0 && errno == 0) - { - errno = ERANGE; - } - return ret; -} - -inline int __cdecl _snprintf_unsafe(char *_Dst, size_t _SizeInWords, size_t _Count, const char *_Format, ...) -{ - int ret; - va_list _ArgList; - va_start(_ArgList, _Format); - ret = _vsnprintf_unsafe(_Dst, _SizeInWords, _Count, _Format, _ArgList); - va_end(_ArgList); - return ret; -} - inline errno_t __cdecl _wfopen_unsafe(PAL_FILE * *ff, const WCHAR *fileName, const WCHAR *mode) { PAL_FILE *result = _wfopen(fileName, mode); diff --git a/src/pal/inc/rt/safecrt.h b/src/pal/inc/rt/safecrt.h index 3cc10cef33..ab3e37ec48 100644 --- a/src/pal/inc/rt/safecrt.h +++ b/src/pal/inc/rt/safecrt.h @@ -3253,10 +3253,6 @@ int __cdecl vswprintf_s(WCHAR (&_Dst)[_SizeInWords], const WCHAR *_Format, va_li * return -1 if the formatted string does not entirely fit into _Dst (we will not call _SAFECRT_INVALID_PARAMETER); * if _Count == 0, then (_Dst == nullptr && _SizeInBytes == 0) is allowed */ -_SAFECRT__EXTERN_C -int __cdecl _snprintf_s(char *_Dst, size_t _SizeInBytes, size_t _Count, const char *_Format, ...); -_SAFECRT__EXTERN_C -int __cdecl _vsnprintf_s(char *_Dst, size_t _SizeInBytes, size_t _Count, const char *_Format, va_list _ArgList); #if defined(__cplusplus) && _SAFECRT_USE_CPP_OVERLOADS template <size_t _SizeInBytes> |