#define _wcsstr wcsstr
#endif // !PAL_STDCPP_COMPAT
-#ifdef PLATFORM_UNIX
-#define _vsnprintf vsnprintf
-#endif
-
#define ___in _SAL1_Source_(__in, (), _In_)
#define ___out _SAL1_Source_(__out, (), _Out_)
va_list args)
{
char str[4096];
- int length = PAL__vsnprintf(str, sizeof(str), format, args);
+ int length = _vsnprintf_s(str, sizeof(str), _TRUNCATE, format, args);
if (length > 0)
{
return Output(mask, "%s", str);
PAL__flushall
PAL_free
PAL_fwprintf
-PAL_swprintf
PAL_GetPALDirectoryW
PAL_GetResourceString
PAL_get_stdout
PAL_qsort
PAL_Reenter
PAL_fprintf
-PAL__vsnprintf
PAL__wcstoui64
PAL_wcstoul
PAL_iswprint
_stricmp
sprintf_s
swprintf_s
+vsprintf_s
+_snprintf_s
_snwprintf_s
_vsnprintf_s
_vsnwprintf_s
#define UNREFERENCED_PARAMETER(P) (void)(P)
#ifdef PLATFORM_UNIX
-#define _vsnprintf vsnprintf
+#define _vsnprintf_s(string, sizeInBytes, count, format, args) vsnprintf(string, sizeInBytes, format, args)
#define sprintf_s snprintf
#define swprintf_s swprintf
#endif
int pid_len = sprintf_s (&pBuffer[buffer_start], BUFFERSIZE - buffer_start, "[%5d]", (uint32_t)GCToOSInterface::GetCurrentThreadIdForLogging());
buffer_start += pid_len;
memset(&pBuffer[buffer_start], '-', BUFFERSIZE - buffer_start);
- int msg_len = _vsnprintf(&pBuffer[buffer_start], BUFFERSIZE - buffer_start, fmt, args );
+ int msg_len = _vsnprintf_s(&pBuffer[buffer_start], BUFFERSIZE - buffer_start, _TRUNCATE, fmt, args );
if (msg_len == -1)
{
msg_len = BUFFERSIZE - buffer_start;
{
if (FAILED(hr = m_output.ReSizeNoThrow(STRING_BUFFER_LEN * i)))
return 0;
- count = _vsnprintf((char *)m_output.Ptr(), STRING_BUFFER_LEN * i, str, marker);
+ va_list markerCopy;
+ va_copy(markerCopy, marker);
+ count = _vsnprintf_s((char *)m_output.Ptr(), STRING_BUFFER_LEN * i, _TRUNCATE, str, markerCopy);
+ va_end(markerCopy);
i *= 2;
}
OutputDebugStringA((LPCSTR)m_output.Ptr());
#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
#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
#define _close PAL__close
#define _wcstoui64 PAL__wcstoui64
#define _flushall PAL__flushall
-#define _vsnprintf PAL__vsnprintf
#define strnlen PAL_strnlen
#ifdef _AMD64_
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);
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);
*/
#define _wcslwr_s _wcslwr_unsafe
-#define _snprintf_s _snprintf_unsafe
#define swscanf_s swscanf
#define _wfopen_s _wfopen_unsafe
#define _vscprintf _vscprintf_unsafe
-#define vsprintf_s _vsnprintf
-
extern "C++" {
#include <safemath.h>
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;
}
}
-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);
* 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>
/*++
Function:
- PAL_swprintf
-
-See MSDN doc.
---*/
-int
-__cdecl
-PAL_swprintf(
- wchar_16 *buffer,
- const wchar_16 *format,
- ...)
-{
- LONG Length;
- va_list ap;
-
- PERF_ENTRY(swprintf);
- ENTRY("PAL_swprintf (buffer=%p, format=%p (%S))\n", buffer, format, format);
-
- va_start(ap, format);
- Length = PAL__wvsnprintf(buffer, 0x7fffffff, format, ap);
- va_end(ap);
-
- LOGEXIT("PAL_swprintf returns int %d\n", Length);
- PERF_EXIT(swprintf);
- return Length;
-}
-
-/*++
-Function:
PAL_swscanf
See MSDN doc.
}
-/*++
-Function:
- PAL_vsprintf
-
-See MSDN doc.
---*/
-int
-__cdecl
-PAL_vsprintf(char *buffer,
- const char *format,
- va_list argptr)
-{
- LONG Length;
-
- PERF_ENTRY(vsprintf);
- ENTRY("PAL_vsprintf (buffer=%p, format=%p (%s), argptr=%p)\n",
- buffer, format, format, argptr);
-
- Length = InternalVsnprintf(CorUnix::InternalGetCurrentThread(), buffer, 0x7fffffff, format, argptr);
-
- LOGEXIT("PAL_vsprintf returns int %d\n", Length);
- PERF_EXIT(vsprintf);
-
- return Length;
-}
-
-
-/*++
-Function:
- PAL_vswprintf
-
-See MSDN doc.
---*/
-int
-__cdecl
-PAL_vswprintf(wchar_16 *buffer,
- const wchar_16 *format,
- va_list argptr)
-{
- LONG Length;
-
- PERF_ENTRY(vswprintf);
- ENTRY("PAL_vswprintf (buffer=%p, format=%p (%S), argptr=%p)\n",
- buffer, format, format, argptr);
-
- Length = PAL__wvsnprintf(buffer, 0x7fffffff, format, argptr);
-
- LOGEXIT("PAL_vswprintf returns int %d\n", Length);
- PERF_EXIT(vswprintf);
-
- return Length;
-}
-
-
#if SSCANF_CANNOT_HANDLE_MISSING_EXPONENT
/*++
Function:
using namespace CorUnix;
-int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR Format, va_list ap);
-int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Format, va_list ap);
int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, va_list ap);
int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *format, va_list ap);
/*******************************************************************************
Function:
- PAL_vsnprintf
-
-Parameters:
- Buffer
- - out buffer
- Count
- - buffer size
- Format
- - format string
- ap
- - stdarg parameter list
-*******************************************************************************/
-
-int __cdecl PAL__vsnprintf(LPSTR Buffer, size_t Count, LPCSTR Format, va_list ap)
-{
- LONG Length;
-
- PERF_ENTRY(PAL__vsnprintf);
- ENTRY("PAL__vsnprintf (buffer=%p, count=%d, format=%p (%s), argptr=%p)\n",
- Buffer, Count, Format, Format, ap);
-
- Length = CoreVsnprintf(InternalGetCurrentThread(), Buffer, Count, Format, ap);
-
- LOGEXIT("PAL__vsnprintf returns int %d\n", Length);
- PERF_EXIT(PAL__vsnprintf);
-
- return Length;
-}
-
-/*******************************************************************************
-Function:
- PAL_wvsnprintf
-
- -- see PAL_vsnprintf above
-*******************************************************************************/
-
-int __cdecl PAL__wvsnprintf(LPWSTR Buffer, size_t Count, LPCWSTR Format, va_list ap)
-{
- return CoreWvsnprintf(InternalGetCurrentThread(), Buffer, Count, Format, ap);
-}
-
-/*******************************************************************************
-Function:
PAL_vfprintf
Parameters:
} // end extern "C"
-int CorUnix::InternalWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR Format, va_list ap)
-{
- return CoreWvsnprintf(pthrCurrent, Buffer, Count, Format, ap);
-}
-
-int CorUnix::InternalVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Format, va_list ap)
-{
- return CoreVsnprintf(pthrCurrent, Buffer, Count, Format, ap);
-}
-
int CorUnix::InternalVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, va_list ap)
{
return CoreVfprintf(pthrCurrent, stream, format, ap);
}
-int CorUnix::InternalVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *format, va_list ap)
-{
- return CoreVfwprintf(pthrCurrent, stream, format, ap);
-}
-
int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *format, va_list aparg)
{
CHAR TempBuff[1024]; /* used to hold a single %<foo> format string */
va_list apcopy;
va_copy(apcopy, ap);
- TempInt = vsnprintf(TempSprintfStr, TEMP_COUNT, TempBuff, apcopy);
+ TempInt = _vsnprintf_s(TempSprintfStr, TEMP_COUNT, _TRUNCATE, TempBuff, apcopy);
va_end(apcopy);
PAL_printf_arg_remover(&ap, Width, Precision, Type, Prefix);
TempSprintfStr = TempSprintfStrPtr;
va_copy(apcopy, ap);
- vsnprintf(TempSprintfStr, TempInt, TempBuff, apcopy);
+ _vsnprintf_s(TempSprintfStr, TempInt, _TRUNCATE, TempBuff, apcopy);
va_end(apcopy);
PAL_printf_arg_remover(&ap, Width, Precision, Type, Prefix);
}
return (written);
}
-int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Format, va_list aparg)
-{
- BOOL BufferRanOut = FALSE;
- CHAR TempBuff[1024]; /* used to hold a single %<foo> format string */
- LPSTR BufferPtr = Buffer;
- LPCSTR Fmt = Format;
- LPWSTR TempWStr;
- LPSTR TempStr;
- WCHAR TempWChar;
- INT Flags;
- INT Width;
- INT Precision;
- INT Prefix;
- INT Type;
- INT Length;
- INT TempInt;
- int wctombResult;
- va_list ap;
-
- va_copy(ap, aparg);
-
- while (*Fmt)
- {
- if (BufferRanOut || (BufferPtr - Buffer) >= static_cast<int>(Count)) //Count is assumed to be in the range of int
- {
- BufferRanOut = TRUE;
- break;
- }
- else if(*Fmt == '%' &&
- TRUE == Internal_ExtractFormatA(pthrCurrent, &Fmt, TempBuff, &Flags,
- &Width, &Precision,
- &Prefix, &Type))
- {
- if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_STRING)
- {
- if (WIDTH_STAR == Width)
- {
- Width = va_arg(ap, INT);
- }
- else if (WIDTH_INVALID == Width)
- {
- /* both a '*' and a number, ignore, but remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- if (PRECISION_STAR == Precision)
- {
- Precision = va_arg(ap, INT);
- }
- else if (PRECISION_INVALID == Precision)
- {
- /* both a '*' and a number, ignore, but remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- TempWStr = va_arg(ap, LPWSTR);
- Length = WideCharToMultiByte(CP_ACP, 0, TempWStr, -1, 0,
- 0, 0, 0);
- if (!Length)
- {
- ASSERT("WideCharToMultiByte failed. Error is %d\n",
- GetLastError());
- va_end(ap);
- return -1;
- }
- TempStr = (LPSTR) InternalMalloc(Length);
- if (!TempStr)
- {
- ERROR("InternalMalloc failed\n");
- pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- va_end(ap);
- return -1;
- }
- if (PRECISION_DOT == Precision)
- {
- /* copy nothing */
- *TempStr = 0;
- Length = 0;
- }
- else if (Precision > 0 && Precision < Length - 1)
- {
- Length = WideCharToMultiByte(CP_ACP, 0, TempWStr,
- Precision, TempStr, Length,
- 0, 0);
- if (!Length)
- {
- ASSERT("WideCharToMultiByte failed. Error is %d\n",
- GetLastError());
- free(TempStr);
- va_end(ap);
- return -1;
- }
- TempStr[Length] = 0;
- Length = Precision;
- }
- /* copy everything */
- else
- {
- wctombResult = WideCharToMultiByte(CP_ACP, 0, TempWStr, -1,
- TempStr, Length, 0, 0);
- if (!wctombResult)
- {
- ASSERT("WideCharToMultiByte failed. Error is %d\n",
- GetLastError());
- free(TempStr);
- va_end(ap);
- return -1;
- }
- --Length; /* exclude null char */
- }
-
- /* do the padding (if needed)*/
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- TempStr,
- Width - Length,
- Flags);
-
- free(TempStr);
- }
- else if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_CHAR)
- {
- CHAR TempBuffer[5];
-
- if (WIDTH_STAR == Width ||
- WIDTH_INVALID == Width)
- {
- /* ignore (because it's a char), and remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
- if (PRECISION_STAR == Precision ||
- PRECISION_INVALID == Precision)
- {
- /* ignore (because it's a char), and remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- TempWChar = va_arg(ap, int);
- Length = WideCharToMultiByte(CP_ACP, 0, &TempWChar, 1,
- TempBuffer, sizeof(TempBuffer),
- 0, 0);
- if (!Length)
- {
- ASSERT("WideCharToMultiByte failed. Error is %d\n",
- GetLastError());
- va_end(ap);
- return -1;
- }
- TempBuffer[Length] = 0;
-
- /* do the padding (if needed)*/
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- TempBuffer,
- Width - Length,
- Flags);
-
- }
- /* this places the number of bytes written to the buffer in the
- next arg */
- else if (Type == PFF_TYPE_N)
- {
- if (WIDTH_STAR == Width)
- {
- Width = va_arg(ap, INT);
- }
- if (PRECISION_STAR == Precision)
- {
- Precision = va_arg(ap, INT);
- }
-
- if (Prefix == PFF_PREFIX_SHORT)
- {
- *(va_arg(ap, short *)) = BufferPtr - Buffer;
- }
- else
- {
- *(va_arg(ap, LPLONG)) = BufferPtr - Buffer;
- }
- }
- else if (Type == PFF_TYPE_CHAR && (Flags & PFF_ZERO) != 0)
- {
- // Some versions of sprintf don't support 0-padded chars,
- // so we handle them here.
- char ch[2];
-
- ch[0] = (char) va_arg(ap, int);
- ch[1] = '\0';
- Length = 1;
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- ch,
- Width - Length,
- Flags);
- }
- else if (Type == PFF_TYPE_STRING && (Flags & PFF_ZERO) != 0)
- {
- // Some versions of sprintf don't support 0-padded strings,
- // so we handle them here.
- char *tempStr;
-
- tempStr = va_arg(ap, char *);
- Length = strlen(tempStr);
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- tempStr,
- Width - Length,
- Flags);
- }
- else
- {
- // Types that sprintf can handle
- size_t TempCount = Count - (BufferPtr - Buffer);
-
-#if !HAVE_LARGE_SNPRINTF_SUPPORT
- // Limit TempCount to 0x40000000, which is sufficient
- // for platforms on which snprintf fails for very large
- // sizes.
- if (TempCount > 0x40000000)
- {
- TempCount = 0x40000000;
- }
-#endif // HAVE_LARGE_SNPRINTF_SUPPORT
-
- TempInt = 0;
- // %h (short) doesn't seem to be handled properly by local sprintf,
- // so we do the truncation ourselves for some cases.
- if (Type == PFF_TYPE_P && Prefix == PFF_PREFIX_SHORT)
- {
- // Convert from pointer -> int -> short to avoid warnings.
- long trunc1;
- short trunc2;
-
- trunc1 = va_arg(ap, LONG);
- trunc2 = (short) trunc1;
- trunc1 = trunc2;
-
- TempInt = snprintf(BufferPtr, TempCount, TempBuff, trunc1);
- }
- else if (Type == PFF_TYPE_INT && Prefix == PFF_PREFIX_SHORT)
- {
- // Convert explicitly from int to short to get
- // correct sign extension for shorts on all systems.
- int n;
- short s;
-
- n = va_arg(ap, int);
- s = (short) n;
-
- TempInt = snprintf(BufferPtr, TempCount, TempBuff, s);
- }
- else
- {
- va_list apcopy;
- va_copy(apcopy, ap);
- TempInt = vsnprintf(BufferPtr, TempCount, TempBuff, apcopy);
- va_end(apcopy);
- PAL_printf_arg_remover(&ap, Width, Precision, Type, Prefix);
- }
-
- if (TempInt < 0 || static_cast<size_t>(TempInt) >= TempCount) /* buffer not long enough */
- {
- BufferPtr += TempCount;
- BufferRanOut = TRUE;
- }
- else
- {
- BufferPtr += TempInt;
- }
- }
- }
- else
- {
- *BufferPtr++ = *Fmt++; /* copy regular chars into buffer */
- }
- }
-
- if (static_cast<int>(Count) > (BufferPtr - Buffer)) //Count is assumed to be in the range of int
- {
- *BufferPtr = 0; /* end the string */
- }
-
- va_end(ap);
-
- if (BufferRanOut)
- {
- errno = ERANGE;
- return -1;
- }
- else
- {
- return BufferPtr - Buffer;
- }
-}
-
-int CoreWvsnprintf(CPalThread *pthrCurrent, LPWSTR Buffer, size_t Count, LPCWSTR Format, va_list aparg)
-{
- BOOL BufferRanOut = FALSE;
- CHAR TempBuff[1024]; /* used to hold a single %<foo> format string */
- LPWSTR BufferPtr = Buffer;
- LPCWSTR Fmt = Format;
- LPWSTR TempWStr = NULL;
- LPWSTR WorkingWStr = NULL;
- WCHAR TempWChar[2];
- INT Flags;
- INT Width;
- INT Precision;
- INT Prefix;
- INT Type;
- INT TempInt;
- LPSTR TempNumberBuffer;
- int mbtowcResult;
- va_list(ap);
-
- PERF_ENTRY(wvsnprintf);
- ENTRY("wvsnprintf (buffer=%p, count=%u, format=%p (%S))\n",
- Buffer, Count, Format, Format);
-
- va_copy(ap, aparg);
-
- while (*Fmt)
- {
- if (BufferRanOut || (BufferPtr - Buffer) >= static_cast<int>(Count)) //Count is assumed to be in the range of int
- {
- BufferRanOut = TRUE;
- break;
- }
- else if(*Fmt == '%' &&
- TRUE == Internal_ExtractFormatW(pthrCurrent, &Fmt, TempBuff, &Flags,
- &Width, &Precision,
- &Prefix, &Type))
- {
- if (((Prefix == PFF_PREFIX_LONG || Prefix == PFF_PREFIX_LONG_W) &&
- (Type == PFF_TYPE_STRING || Type == PFF_TYPE_WSTRING)) ||
- (Prefix == PFF_PREFIX_SHORT && Type == PFF_TYPE_STRING) ||
- (Type == PFF_TYPE_WSTRING && (Flags & PFF_ZERO) != 0))
- {
- BOOL needToFree = FALSE;
-
- if (WIDTH_STAR == Width)
- {
- Width = va_arg(ap, INT);
- }
- else if (WIDTH_INVALID == Width)
- {
- /* both a '*' and a number, ignore, but remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- if (PRECISION_STAR == Precision)
- {
- Precision = va_arg(ap, INT);
- }
- else if (PRECISION_INVALID == Precision)
- {
- /* both a '*' and a number, ignore, but remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- if ((Type == PFF_TYPE_STRING && Prefix == PFF_PREFIX_LONG) ||
- Prefix == PFF_PREFIX_LONG_W)
- {
- TempWStr = va_arg(ap, LPWSTR);
- }
- else
- {
- // %lS and %hs assume an LPSTR argument.
- LPSTR s = va_arg(ap, LPSTR );
- UINT Length = 0;
- Length = MultiByteToWideChar( CP_ACP, 0, s, -1, NULL, 0 );
- if ( Length != 0 )
- {
- TempWStr =
- (LPWSTR)InternalMalloc((Length + 1 ) * sizeof( WCHAR ) );
- if ( TempWStr )
- {
- needToFree = TRUE;
- MultiByteToWideChar( CP_ACP, 0, s, -1,
- TempWStr, Length );
- }
- else
- {
- ERROR( "InternalMalloc failed.\n" );
- va_end(ap);
- return -1;
- }
- }
- else
- {
- ASSERT( "Unable to convert from multibyte "
- " to wide char.\n" );
- va_end(ap);
- return -1;
- }
-
- }
-
- INT Length = PAL_wcslen(TempWStr);
- WorkingWStr = (LPWSTR) InternalMalloc(sizeof(WCHAR) * (Length + 1));
- if (!WorkingWStr)
- {
- ERROR("InternalMalloc failed\n");
- pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- if (needToFree)
- {
- free(TempWStr);
- }
- va_end(ap);
- return -1;
- }
- if (PRECISION_DOT == Precision)
- {
- // Copy nothing
- *WorkingWStr = 0;
- Length = 0;
- }
- else if (Precision > 0 && Precision < Length)
- {
- if (wcsncpy_s(WorkingWStr, (Length + 1), TempWStr, Precision+1) != SAFECRT_SUCCESS)
- {
- ERROR("CoreWvsnprintf failed\n");
- if (needToFree)
- {
- free(TempWStr);
- }
- free(WorkingWStr);
- LOGEXIT("wcsncpy_s failed!\n");
- PERF_EXIT(wvsnprintf);
- va_end(ap);
- return (-1);
- }
-
- Length = Precision;
- }
- else
- {
- // Copy everything
- PAL_wcscpy(WorkingWStr, TempWStr);
- }
-
- // Add padding if needed.
- BufferRanOut = !Internal_AddPaddingW(&BufferPtr,
- Count - (BufferPtr - Buffer),
- WorkingWStr,
- Width - Length,
- Flags);
-
- if (needToFree)
- {
- free(TempWStr);
- }
- free(WorkingWStr);
- }
- else if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_CHAR)
- {
- if (WIDTH_STAR == Width ||
- WIDTH_INVALID == Width)
- {
- /* ignore (because it's a char), and remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- if (PRECISION_STAR == Precision ||
- PRECISION_INVALID == Precision)
- {
- /* ignore (because it's a char), and remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- TempWChar[0] = va_arg(ap, int);
- TempWChar[1] = 0;
-
- /* do the padding (if needed)*/
- BufferRanOut = !Internal_AddPaddingW(&BufferPtr,
- Count - (BufferPtr - Buffer),
- TempWChar,
- Width - 1,
- Flags);
-
- }
- /* this places the number of bytes written to the buffer in the
- next arg */
- else if (Type == PFF_TYPE_N)
- {
- if (WIDTH_STAR == Width)
- {
- Width = va_arg(ap, INT);
- }
- if (PRECISION_STAR == Precision)
- {
- Precision = va_arg(ap, INT);
- }
-
- if (Prefix == PFF_PREFIX_SHORT)
- {
- *(va_arg(ap, short *)) = BufferPtr - Buffer;
- }
- else
- {
- *(va_arg(ap, LPLONG)) = BufferPtr - Buffer;
- }
- }
- else
- {
- // Types that sprintf can handle
-
- /* note: I'm using the wide buffer as a (char *) buffer when I
- pass it to sprintf(). After I get the buffer back I make a
- backup of the chars copied and then convert them to wide
- and place them in the buffer (BufferPtr) */
- size_t TempCount = Count - (BufferPtr - Buffer);
- TempInt = 0;
-
-#if !HAVE_LARGE_SNPRINTF_SUPPORT
- // Limit TempCount to 0x40000000, which is sufficient
- // for platforms on which snprintf fails for very large
- // sizes.
- if (TempCount > 0x40000000)
- {
- TempCount = 0x40000000;
- }
-#endif // HAVE_LARGE_SNPRINTF_SUPPORT
-
- // %h (short) doesn't seem to be handled properly by local sprintf,
- // so we do the truncation ourselves for some cases.
- if (Type == PFF_TYPE_P && Prefix == PFF_PREFIX_SHORT)
- {
- // Convert from pointer -> int -> short to avoid warnings.
- long trunc1;
- short trunc2;
-
- trunc1 = va_arg(ap, LONG);
- trunc2 = (short)trunc1;
- trunc1 = trunc2;
-
- TempInt = snprintf((LPSTR)BufferPtr, TempCount, TempBuff, trunc1);
- }
- else if (Type == PFF_TYPE_INT && Prefix == PFF_PREFIX_SHORT)
- {
- // Convert explicitly from int to short to get
- // correct sign extension for shorts on all systems.
- int n;
- short s;
-
- n = va_arg(ap, int);
- s = (short) n;
-
- TempInt = snprintf((LPSTR)BufferPtr, TempCount, TempBuff, s);
- }
- else
- {
- va_list apcopy;
- va_copy(apcopy, ap);
- TempInt = vsnprintf((LPSTR) BufferPtr, TempCount, TempBuff, apcopy);
- va_end(apcopy);
- PAL_printf_arg_remover(&ap, Width, Precision, Type, Prefix);
- }
-
- if (TempInt == 0)
- {
- // The argument is "".
- continue;
- }
- if (TempInt < 0 || static_cast<size_t>(TempInt) >= TempCount) /* buffer not long enough */
- {
- TempNumberBuffer = (LPSTR) InternalMalloc(TempCount+1);
- if (!TempNumberBuffer)
- {
- ERROR("InternalMalloc failed\n");
- pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- errno = ENOMEM;
- va_end(ap);
- return -1;
- }
-
- if (strncpy_s(TempNumberBuffer, TempCount+1, (LPSTR) BufferPtr, TempCount) != SAFECRT_SUCCESS)
- {
- ASSERT("strncpy_s failed!\n");
- free(TempNumberBuffer);
- va_end(ap);
- return -1;
- }
-
- mbtowcResult = MultiByteToWideChar(CP_ACP, 0,
- TempNumberBuffer,
- TempCount,
- BufferPtr, TempCount);
- if (!mbtowcResult)
- {
- ASSERT("MultiByteToWideChar failed. Error is %d\n",
- GetLastError());
- free(TempNumberBuffer);
- va_end(ap);
- return -1;
- }
- BufferPtr += TempCount;
- BufferRanOut = TRUE;
- }
- else
- {
- TempNumberBuffer = (LPSTR) InternalMalloc(TempInt+1);
- if (!TempNumberBuffer)
- {
- ERROR("InternalMalloc failed\n");
- pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY);
- va_end(ap);
- return -1;
- }
-
- if (strncpy_s(TempNumberBuffer, TempInt+1, (LPSTR) BufferPtr, TempInt) != SAFECRT_SUCCESS)
- {
- ASSERT("strncpy_s failed!\n");
- free(TempNumberBuffer);
- va_end(ap);
- return -1;
- }
-
- mbtowcResult = MultiByteToWideChar(CP_ACP, 0,
- TempNumberBuffer,
- TempInt,
- BufferPtr, TempInt);
- if (!mbtowcResult)
- {
- ASSERT("MultiByteToWideChar failed. Error is %d\n",
- GetLastError());
- free(TempNumberBuffer);
- va_end(ap);
- return -1;
- }
- BufferPtr += TempInt;
- }
- free(TempNumberBuffer);
- }
- }
- else
- {
- *BufferPtr++ = *Fmt++; /* copy regular chars into buffer */
- }
- }
-
- if (static_cast<int>(Count) > (BufferPtr - Buffer)) //Count is assumed to be in the range of int
- {
- *BufferPtr = 0; /* end the string */
- }
-
- va_end(ap);
-
- if (BufferRanOut)
- {
- errno = ERANGE;
- return -1;
- }
- else
- {
- return BufferPtr - Buffer;
- }
-}
-
int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, va_list aparg)
{
CHAR TempBuff[1024]; /* used to hold a single %<foo> format string */
static size_t Silent_PAL_wcslen(const wchar_16 *string);
-/*******************************************************************************
-Function:
- PAL_vsnprintf (silent version)
- for more details, see PAL_vsnprintf in printf.c
-*******************************************************************************/
-INT Silent_PAL_vsnprintf(LPSTR Buffer, INT Count, LPCSTR Format, va_list aparg)
-{
- BOOL BufferRanOut = FALSE;
- CHAR TempBuff[1024]; /* used to hold a single %<foo> format string */
- LPSTR BufferPtr = Buffer;
- LPCSTR Fmt = Format;
- LPWSTR TempWStr;
- CHAR TempStr[MAX_STR_LEN+1];
- WCHAR TempWChar;
- INT Flags;
- INT Width;
- INT Precision;
- INT Prefix;
- INT Type;
- INT Length;
- INT TempInt;
- int wctombResult;
- va_list ap;
-
- va_copy(ap, aparg);
-
- while (*Fmt)
- {
- if ((BufferPtr - Buffer) >= Count)
- {
- BufferRanOut = TRUE;
- break;
- }
- else if(*Fmt == '%' &&
- TRUE == Silent_ExtractFormatA(&Fmt, TempBuff, &Flags,
- &Width, &Precision,
- &Prefix, &Type))
- {
- if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_STRING)
- {
- if (WIDTH_STAR == Width)
- {
- Width = va_arg(ap, INT);
- }
- else if (WIDTH_INVALID == Width)
- {
- /* both a '*' and a number, ignore, but remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- if (PRECISION_STAR == Precision)
- {
- Precision = va_arg(ap, INT);
- }
- else if (PRECISION_INVALID == Precision)
- {
- /* both a '*' and a number, ignore, but remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- TempWStr = va_arg(ap, LPWSTR);
- Length = Silent_WideCharToMultiByte(TempWStr, -1, 0, 0);
- if (!Length)
- {
- va_end(ap);
- return -1;
- }
-
- /* clip string output to MAX_STR_LEN characters */
- if (PRECISION_DOT == Precision)
- {
- Precision = MAX_STR_LEN;
- }
-
- if (PRECISION_DOT == Precision)
- {
- /* copy nothing */
- *TempStr = 0;
- Length = 0;
- }
- else if (Precision > 0 && Precision < Length - 1)
- {
- Length = Silent_WideCharToMultiByte(TempWStr, Precision,
- TempStr, Length);
- if (!Length)
- {
- va_end(ap);
- return -1;
- }
- TempStr[Length] = 0;
- Length = Precision;
- }
- /* copy everything */
- else
- {
- wctombResult = Silent_WideCharToMultiByte(TempWStr, -1,
- TempStr, Length);
- if (!wctombResult)
- {
- PAL_free(TempStr);
- va_end(ap);
- return -1;
- }
- --Length; /* exclude null char */
- }
-
- /* do the padding (if needed)*/
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- TempStr,
- Width - Length,
- Flags);
- }
- else if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_CHAR)
- {
- CHAR TempBuffer[4];
-
- if (WIDTH_STAR == Width ||
- WIDTH_INVALID == Width)
- {
- /* ignore (because it's a char), and remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
- if (PRECISION_STAR == Precision ||
- PRECISION_INVALID == Precision)
- {
- /* ignore (because it's a char), and remove arg */
- TempInt = va_arg(ap, INT); /* value not used */
- }
-
- TempWChar = va_arg(ap, int);
- Length = Silent_WideCharToMultiByte(&TempWChar, 1, TempBuffer, 4);
- if (!Length)
- {
- va_end(ap);
- return -1;
- }
- TempBuffer[Length] = 0;
-
- /* do the padding (if needed)*/
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- TempBuffer,
- Width - Length,
- Flags);
-
- }
- /* this places the number of bytes written to the buffer in the
- next arg */
- else if (Type == PFF_TYPE_N)
- {
- if (WIDTH_STAR == Width)
- {
- Width = va_arg(ap, INT);
- }
- if (PRECISION_STAR == Precision)
- {
- Precision = va_arg(ap, INT);
- }
- if (Prefix == PFF_PREFIX_SHORT)
- {
- *(va_arg(ap, short *)) = BufferPtr - Buffer;
- }
- else
- {
- *(va_arg(ap, LPLONG)) = BufferPtr - Buffer;
- }
- }
- else if (Type == PFF_TYPE_CHAR && (Flags & PFF_ZERO) != 0)
- {
- // Some versions of sprintf don't support 0-padded chars,
- // so we handle them here.
- char ch[2];
-
- ch[0] = (char) va_arg(ap, int);
- ch[1] = '\0';
- Length = 1;
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- ch,
- Width - Length,
- Flags);
- }
- else if (Type == PFF_TYPE_STRING && (Flags & PFF_ZERO) != 0)
- {
- // Some versions of sprintf don't support 0-padded strings,
- // so we handle them here.
- char *tempStr;
-
- tempStr = va_arg(ap, char *);
- Length = strlen(tempStr);
- BufferRanOut = !Internal_AddPaddingA(&BufferPtr,
- Count - (BufferPtr - Buffer),
- tempStr,
- Width - Length,
- Flags);
- }
- /* types that sprintf can handle */
- else
- {
- size_t TempCount = Count - (BufferPtr - Buffer);
-
- TempInt = 0;
- /* %h (short) doesn't seem to be handled properly by local sprintf,
- so lets do the truncation ourselves. (ptr -> int -> short to avoid
- warnings */
- if (Type == PFF_TYPE_P && Prefix == PFF_PREFIX_SHORT)
- {
- long trunc1;
- short trunc2;
-
- trunc1 = va_arg(ap, LONG);
- trunc2 = (short)trunc1;
-
- TempInt = snprintf(BufferPtr, TempCount, TempBuff, trunc2);
- }
- else if (Type == PFF_TYPE_INT && Prefix == PFF_PREFIX_SHORT)
- {
- // Convert explicitly from int to short to get
- // correct sign extension for shorts on all systems.
- int n;
- short s;
-
- n = va_arg(ap, int);
- s = (short) n;
-
- TempInt = snprintf(BufferPtr, TempCount, TempBuff, s);
- }
- else
- {
- /* limit string output (%s) to 300 characters */
- if(TempBuff[0] == '%' && TempBuff[1] == 's')
- {
- if (strcpy_s(TempBuff, sizeof(TempBuff), "%.300s") != SAFECRT_SUCCESS)
- {
- va_end(ap);
- return -1;
- }
- }
- va_list apcopy;
- va_copy(apcopy, ap);
- TempInt = InternalVsnprintf(CorUnix::InternalGetCurrentThread(), BufferPtr, TempCount, TempBuff, apcopy);
- va_end(apcopy);
- PAL_printf_arg_remover(&ap, Width, Precision, Type, Prefix);
- }
-
- if (TempInt < 0 || static_cast<size_t>(TempInt) >= TempCount) /* buffer not long enough */
- {
- BufferPtr += TempCount;
- BufferRanOut = TRUE;
- }
- else
- {
- BufferPtr += TempInt;
- }
- }
- }
- else
- {
- *BufferPtr++ = *Fmt++; /* copy regular chars into buffer */
- }
- }
-
- if (Count > (BufferPtr - Buffer))
- {
- *BufferPtr = 0; /* end the string */
- }
-
- va_end(ap);
-
- if (BufferRanOut)
- {
- return -1;
- }
- else
- {
- return BufferPtr - Buffer;
- }
-}
-
/*++
Function:
PAL_vfprintf (silent version)
PERF_ENTRY(atol);
ENTRY("atol (szNumber=%p (%s))\n",
- szNumber?szNumber:"NULL"
+ szNumber, szNumber?szNumber:"NULL"
);
lResult = atol(szNumber);
#undef vfwprintf
#undef vprintf
#undef wprintf
-#undef swprintf
#undef wcstod
#undef wcstol
#undef wcstoul
#undef iswspace
#undef towlower
#undef towupper
-#undef vsprintf
-#undef vswprintf
-#undef _vsnprintf
-#undef vsnprintf
#undef wvsnprintf
#ifdef _AMD64_
extern "C"
{
int
- __cdecl
- PAL__vsnprintf(
- LPSTR Buffer,
- size_t Count,
- LPCSTR Format,
- va_list ap);
-
- int
- __cdecl
- PAL__wvsnprintf(
- LPWSTR Buffer,
- size_t Count,
- LPCWSTR Format,
- va_list ap);
-
- int
__cdecl
PAL_vfprintf(
PAL_FILE *stream,
const char *format,
va_list ap);
- int
- InternalWvsnprintf(
- CPalThread *pthrCurrent,
- LPWSTR Buffer,
- size_t Count,
- LPCWSTR Format,
- va_list ap);
-
- int
- InternalVsnprintf(
- CPalThread *pthrCurrent,
- LPSTR Buffer,
- size_t Count,
- LPCSTR Format,
- va_list ap);
-
- int
- InternalVfwprintf(
- CPalThread *pthrCurrent,
- PAL_FILE *stream,
- const wchar_16 *format,
- va_list ap);
-
}
#else // __cplusplus
- int
- __cdecl
- PAL__vsnprintf(
- LPSTR Buffer,
- size_t Count,
- LPCSTR Format,
- va_list ap);
-
- int
- __cdecl
- PAL__wvsnprintf(
- LPWSTR Buffer,
- size_t Count,
- LPCWSTR Format,
- va_list ap);
-
int
__cdecl
PAL_vfprintf(
va_start(args, format);
- output_size+=Silent_PAL_vsnprintf(buffer_ptr, DBG_BUFFER_SIZE-output_size,
- format, args);
+ output_size+=_vsnprintf_s(buffer_ptr, DBG_BUFFER_SIZE-output_size, _TRUNCATE,
+ format, args);
va_end(args);
if( output_size > DBG_BUFFER_SIZE )
}
va_start(args, format);
- output_size+=Silent_PAL_vsnprintf(buffer_ptr, DBG_BUFFER_SIZE-output_size,
- format, args);
+ output_size+=_vsnprintf_s(buffer_ptr, DBG_BUFFER_SIZE-output_size, _TRUNCATE,
+ format, args);
va_end(args);
if(output_size>DBG_BUFFER_SIZE)
const int cchBuffer = 4096;
char *szBuffer = (char*)alloca(cchBuffer);
- PAL__vsnprintf(szBuffer, cchBuffer, szTextFormat, args);
+ _vsnprintf_s(szBuffer, cchBuffer, _TRUNCATE, szTextFormat, args);
PAL_DisplayDialog(szTitle, szBuffer);
va_end(args);
UINT nFormatLength = 0;
int nBufferLength = 0;
- TRACE( "FMTMSG_ProcessPrintf( %C, %S, %S )\n", c,
+ TRACE( "FMTMSG_ProcessPrintf( %C, %S, %p )\n", c,
lpPrintfString, lpInsertString );
switch ( c )
LPWSTR lpReturnString = NULL;
LPWSTR lpWorkingString = NULL;
-
PERF_ENTRY(FormatMessageW);
ENTRY( "FormatMessageW(dwFlags=%#x, lpSource=%p, dwMessageId=%#x, "
"dwLanguageId=%#x, lpBuffer=%p, nSize=%u, va_list=%p)\n",
add_subdirectory(_stricmp)
add_subdirectory(_strlwr)
add_subdirectory(_strnicmp)
-add_subdirectory(_vsnprintf)
+add_subdirectory(_vsnprintf_s)
add_subdirectory(_vsnwprintf_s)
add_subdirectory(_wcsicmp)
add_subdirectory(_wcslwr)
+++ /dev/null
-cmake_minimum_required(VERSION 2.8.12.2)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(SOURCES
- test5.cpp
-)
-
-add_executable(paltest_vsnprintf_test5
- ${SOURCES}
-)
-
-add_dependencies(paltest_vsnprintf_test5 coreclrpal)
-
-target_link_libraries(paltest_vsnprintf_test5
- pthread
- m
- coreclrpal
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*=====================================================================
-**
-** Source: test5.c
-**
-** Purpose: Test #5 for the _vsnprintf function.
-**
-**
-**===================================================================*/
-
-#include <palsuite.h>
-#include "../_vsnprintf.h"
-
-/*
- * Notes: memcmp is used, as is strlen.
- */
-
-static void DoTest(char *formatstr, int param, char *checkstr)
-{
- char buf[256] = { 0 };
- int n = -1;
-
- Testvsnprintf(buf, 256, formatstr, &n);
-
- if (n != param)
- {
- Fail("ERROR: Expected count parameter to resolve to %d, got %X\n",
- param, n);
- }
- if (memcmp(buf, checkstr, strlen(buf) + 1) != 0)
- {
- Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf);
- }
-}
-
-static void DoShortTest(char *formatstr, int param, char *checkstr)
-{
- char buf[256] = { 0 };
- short int n = -1;
-
- Testvsnprintf(buf, 256, formatstr, &n);
-
- if (n != param)
- {
- Fail("ERROR: Expected count parameter to resolve to %d, got %X\n",
- param, n);
- }
- if (memcmp(buf, checkstr, strlen(buf) + 1) != 0)
- {
- Fail("ERROR: Expected \"%s\" got \"%s\".\n", checkstr, buf);
- }
-}
-
-int __cdecl main(int argc, char *argv[])
-{
- if (PAL_Initialize(argc, argv) != 0)
- {
- return(FAIL);
- }
-
- DoTest("foo %n bar", 4, "foo bar");
- DoTest("foo %#n bar", 4, "foo bar");
- DoTest("foo % n bar", 4, "foo bar");
- DoTest("foo %+n bar", 4, "foo bar");
- DoTest("foo %-n bar", 4, "foo bar");
- DoTest("foo %0n bar", 4, "foo bar");
- DoShortTest("foo %hn bar", 4, "foo bar");
- DoTest("foo %ln bar", 4, "foo bar");
- DoTest("foo %Ln bar", 4, "foo bar");
- DoTest("foo %I64n bar", 4, "foo bar");
- DoTest("foo %20.3n bar", 4, "foo bar");
-
- PAL_Terminate();
- return PASS;
-}
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-# See the LICENSE file in the project root for more information.
-
-Version = 1.0
-Section = C Runtime
-Function = _vsnprintf
-Name = Positive Test for _vsnprintf
-TYPE = DEFAULT
-EXE1 = test5
-Description
-= Tests the PAL implementation of the _vsnprintf function.
-= Tests _vsnprintf with the count specifier.
-= This test is modeled after sprintf_s.
add_subdirectory(test2)
add_subdirectory(test3)
add_subdirectory(test4)
-add_subdirectory(test5)
add_subdirectory(test6)
add_subdirectory(test7)
add_subdirectory(test8)
/*============================================================================
**
-** Source: _vsnprintf.h
+** Source: _vsnprintf_s.h
**
** Purpose: Contains common testing functions for _vsnprintf
**
va_list arglist;
va_start(arglist, format);
- retVal = _vsnprintf(buf, count, format, arglist);
+ retVal = _vsnprintf_s(buf, count, _TRUNCATE, format, arglist);
va_end(arglist);
return (retVal);
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
{
Fail("ERROR: expected negative return value, got %d", ret);
}
- if (memcmp(checkstr, buf, 8) != 0 || buf[8] != 'x')
+ if (memcmp(checkstr, buf, 7) != 0 || buf[7] != 0)
{
Fail("ERROR: expected %s (up to %d chars), got %s\n", checkstr, 8, buf);
}
-
+
PAL_Terminate();
return PASS;
}
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
*/
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
*/
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
**===================================================================*/
#include <palsuite.h>
-#include "../_vsnprintf.h"
+#include "../_vsnprintf_s.h"
/*
* Notes: memcmp is used, as is strlen.
add_subdirectory(test2)
add_subdirectory(test3)
add_subdirectory(test4)
-add_subdirectory(test5)
add_subdirectory(test6)
add_subdirectory(test7)
add_subdirectory(test8)
{
WCHAR buf[256] = { 0 };
- swprintf(buf, formatstr, param);
+ swprintf_s(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, wcslen(checkstr) * 2 + 2) != 0)
{
{
WCHAR buf[256] = { 0 };
- swprintf(buf, formatstr, param);
+ swprintf_s(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, wcslen(checkstr) * 2 + 2) != 0)
{
{
WCHAR buf[256] = { 0 };
- swprintf(buf, formatstr, param);
+ swprintf_s(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0)
{
Fail("ERROR: failed to insert pointer to %#p into \"%s\"\n"
}
}
-void DoCountTest(const WCHAR *formatstr, int param, const WCHAR *checkstr)
-{
- WCHAR buf[512] = { 0 };
- int n = -1;
-
- swprintf(buf, formatstr, &n);
-
- if (n != param)
- {
- Fail("ERROR: Expected count parameter to resolve to %d, got %d\n",
- param, n);
- }
-
- if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0)
- {
- Fail("ERROR: Expected \"%s\" got \"%s\".\n",
- convertC(checkstr), convertC(buf));
- }
-}
-
-void DoShortCountTest(const WCHAR *formatstr, int param, const WCHAR *checkstr)
-{
- WCHAR buf[256] = { 0 };
- short int n = -1;
-
- swprintf(buf, formatstr, &n);
-
- if (n != param)
- {
- Fail("ERROR: Expected count parameter to resolve to %d, got %d\n",
- param, n);
- }
-
- if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0)
- {
- Fail("ERROR: Expected \"%s\" got \"%s\".\n",
- convertC(checkstr), convertC(buf));
- }
-}
-
void DoCharTest(const WCHAR *formatstr, char param, const WCHAR *checkstr)
{
WCHAR buf[256] = { 0 };
- swprintf(buf, formatstr, param);
+ swprintf_s(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0)
{
Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n"
{
WCHAR buf[256] = { 0 };
- swprintf(buf, formatstr, param);
+ swprintf_s(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, wcslen(checkstr)*2 + 2) != 0)
{
Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n"
{
WCHAR buf[256] = { 0 };
- swprintf(buf, formatstr, value);
+ swprintf_s(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr, wcslen(checkstr)* 2 + 2) != 0)
{
Fail("ERROR: failed to insert %#x into \"%s\"\n"
{
WCHAR buf[256] = { 0 };
- swprintf(buf, formatstr, param);
+ swprintf_s(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0)
{
Fail("ERROR: failed to insert %s into \"%s\"\n"
{
WCHAR buf[256] = { 0 };
- swprintf(buf, formatstr, value);
+ swprintf_s(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr1, wcslen(checkstr1)*2 + 2) != 0 &&
memcmp(buf, checkstr2, wcslen(checkstr2)*2 + 2) != 0)
{
{
WCHAR buf[256];
- swprintf(buf, formatstr, precision, param);
+ swprintf_s(buf, _countof(buf), formatstr, precision, param);
if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 &&
memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0)
{
{
WCHAR buf[256];
- swprintf(buf, formatstr, precision, param);
+ swprintf_s(buf, _countof(buf), formatstr, precision, param);
if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 &&
memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0)
{
}
checkstr = convert("hello world");
- swprintf(buf, convert("hello world"));
+ swprintf_s(buf, _countof(buf), convert("hello world"));
if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0)
{
convert("ba"), convert("ba"));
DoArgumentPrecTest(convert("%.*S"), 2, (void*)"bar", "bar", convert("ba"),
convert("ba"));
- DoArgumentPrecTest(convert("%.*n"), 3, (void*)&n, "pointer to int", convert(""),
- convert(""));
- if (n != 0)
- {
- Fail("ERROR: Expected count parameter to resolve to %d, got %X\n",
- 0, n);
- }
-
DoArgumentPrecTest(convert("%.*c"), 0, (void*)'a', "a", convert("a"),
convert("a"));
DoArgumentPrecTest(convert("%.*c"), 4, (void*)'a', "a", convert("a"),
+++ /dev/null
-cmake_minimum_required(VERSION 2.8.12.2)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(SOURCES
- test5.cpp
-)
-
-add_executable(paltest_swprintf_test5
- ${SOURCES}
-)
-
-add_dependencies(paltest_swprintf_test5 coreclrpal)
-
-target_link_libraries(paltest_swprintf_test5
- pthread
- m
- coreclrpal
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================================
-**
-** Source: test5.c
-**
-** Purpose:Tests swprintf with the count specifier
-**
-**
-**==========================================================================*/
-
-
-
-#include <palsuite.h>
-#include "../swprintf.h"
-
-/*
- * Uses memcmp & wcslen
- */
-
-int __cdecl main(int argc, char *argv[])
-{
- WCHAR *longStr;
- WCHAR *longResult;
-
- if (PAL_Initialize(argc, argv) != 0)
- {
- return FAIL;
- }
-
- longStr =
- convert("really-long-string-that-just-keeps-going-on-and-on-and-on.."
- "..................useless-filler.................................."
- "..................useless-filler.................................."
- "..................useless-filler.................................."
- "%n bar");
- longResult =
- convert("really-long-string-that-just-keeps-going-on-and-on-and-on.."
- "..................useless-filler.................................."
- "..................useless-filler.................................."
- "..................useless-filler.................................."
- " bar");
-
- DoCountTest(convert("foo %n bar"), 4, convert("foo bar"));
- DoCountTest(longStr, 257, longResult);
- DoCountTest(convert("fo%n bar"), 2, convert("fo bar"));
- DoCountTest(convert("%n"), 0, convert(""));
- DoCountTest(convert("foo %#n bar"), 4, convert("foo bar"));
- DoCountTest(convert("foo % n bar"), 4, convert("foo bar"));
- DoCountTest(convert("foo %+n bar"), 4, convert("foo bar"));
- DoCountTest(convert("foo %-n bar"), 4, convert("foo bar"));
- DoCountTest(convert("foo %0n bar"), 4, convert("foo bar"));
- DoShortCountTest(convert("foo %hn bar"), 4, convert("foo bar"));
- DoCountTest(convert("foo %ln bar"), 4, convert("foo bar"));
- DoCountTest(convert("foo %Ln bar"), 4, convert("foo bar"));
- DoCountTest(convert("foo %I64n bar"), 4, convert("foo bar"));
- DoCountTest(convert("foo %20.3n bar"), 4, convert("foo bar"));
-
- PAL_Terminate();
-
- free(longStr);
- free(longResult);
-
- return PASS;
-}
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-# See the LICENSE file in the project root for more information.
-
-Version = 1.0
-Section = C Runtime
-Function = swprintf
-Name = Positive Test for swprintf
-TYPE = DEFAULT
-EXE1 = test5
-Description
-= Tests swprintf with the count specifier
add_subdirectory(test2)
add_subdirectory(test3)
add_subdirectory(test4)
-add_subdirectory(test5)
add_subdirectory(test6)
add_subdirectory(test7)
add_subdirectory(test8)
return(FAIL);
}
- testvsp(buf, "hello world");
+ testvsp(buf, _countof(buf), "hello world");
if (memcmp(checkstr, buf, strlen(checkstr)+1) != 0)
{
checkstr, 256, buf);
}
- testvsp(buf, "xxxxxxxxxxxxxxxxx");
- ret = testvsp(buf, "hello world");
+ testvsp(buf, _countof(buf), "xxxxxxxxxxxxxxxxx");
+ ret = testvsp(buf, _countof(buf), "hello world");
if (ret != strlen(checkstr))
{
+++ /dev/null
-cmake_minimum_required(VERSION 2.8.12.2)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(SOURCES
- test5.cpp
-)
-
-add_executable(paltest_vsprintf_test5
- ${SOURCES}
-)
-
-add_dependencies(paltest_vsprintf_test5 coreclrpal)
-
-target_link_libraries(paltest_vsprintf_test5
- pthread
- m
- coreclrpal
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*=====================================================================
-**
-** Source: test5.c
-**
-** Purpose: Test #5 for the vsprintf function.
-**
-**
-**===================================================================*/
-
-#include <palsuite.h>
-#include "../vsprintf.h"
-
-/*
- * Notes: memcmp is used, as is strlen.
- */
-
-
-int __cdecl main(int argc, char *argv[])
-{
- if (PAL_Initialize(argc, argv) != 0)
- {
- return(FAIL);
- }
-
- DoTest("foo %n bar", 4, "foo bar");
- DoTest("foo %#n bar", 4, "foo bar");
- DoTest("foo % n bar", 4, "foo bar");
- DoTest("foo %+n bar", 4, "foo bar");
- DoTest("foo %-n bar", 4, "foo bar");
- DoTest("foo %0n bar", 4, "foo bar");
- DoShortTest("foo %hn bar", 4, "foo bar");
- DoTest("foo %ln bar", 4, "foo bar");
- DoTest("foo %Ln bar", 4, "foo bar");
- DoTest("foo %I64n bar", 4, "foo bar");
- DoTest("foo %20.3n bar", 4, "foo bar");
-
- PAL_Terminate();
- return PASS;
-}
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-# See the LICENSE file in the project root for more information.
-
-Version = 1.0
-Section = C Runtime
-Function = vsprintf
-Name = Positive Test for vsprintf
-TYPE = DEFAULT
-EXE1 = test5
-Description
-= Tests the PAL implementation of the vsprintf function.
-= Tests vsprintf with the count specifier.
-= This test is modeled after _snprintf.
#define __VSPRINTF_H__
/* These functions leaks memory like crazy. C'est la vie. */
-int testvsp(char* buf, const char* format, ...)
+int testvsp(char* buf, size_t buffSize, const char* format, ...)
{
int retVal;
va_list arglist;
va_start(arglist, format);
- retVal = vsprintf(buf, format, arglist);
+ retVal = _vsnprintf_s(buf, buffSize, _TRUNCATE, format, arglist);
va_end(arglist);
return (retVal);
{
char buf[256] = { 0 };
- testvsp(buf, formatstr, param);
+ testvsp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, strlen(buf) + 1) != 0)
{
Fail("ERROR: failed to insert string \"%s\" into \"%s\"\n"
{
char buf[256] = { 0 };
- testvsp(buf, formatstr, param);
+ testvsp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, strlen(buf) + 1) != 0)
{
Fail("ERROR: failed to insert wide string \"%s\" into \"%s\"\n"
{
char buf[256] = { 0 };
- testvsp(buf, formatstr, param);
+ testvsp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, strlen(buf) + 1) != 0)
{
Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n"
{
char buf[256] = { 0 };
- testvsp(buf, formatstr, param);
+ testvsp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, strlen(buf) + 1) != 0)
{
Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n"
{
char buf[256] = { 0 };
- testvsp(buf, formatstr, value);
+ testvsp(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr, strlen(buf) + 1) != 0)
{
Fail("ERROR: failed to insert %#x into \"%s\"\n"
{
char buf[256] = { 0 };
- testvsp(buf, formatstr, value);
+ testvsp(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr, strlen(buf) + 1) != 0)
{
Fail("ERROR: failed to insert %s into \"%s\"\n"
{
char buf[256] = { 0 };
- testvsp(buf, formatstr, value);
+ testvsp(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 &&
memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0)
{
{
char buf[256];
- testvsp(buf, formatstr, precision, param);
+ testvsp(buf, _countof(buf), formatstr, precision, param);
if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 &&
memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0)
{
{
char buf[256];
- testvsp(buf, formatstr, precision, param);
+ testvsp(buf, _countof(buf), formatstr, precision, param);
if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0 &&
memcmp(buf, checkstr2, strlen(checkstr2) + 1) != 0)
{
{
char buf[256] = { 0 };
- testvsp(buf, formatstr, param);
+ testvsp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr1, strlen(checkstr1) + 1))
{
Fail("ERROR: failed to insert %s into \"%s\"\n"
{
char buf[256] = { 0 };
- testvsp(buf, formatstr, value);
+ testvsp(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr1, strlen(checkstr1) + 1) != 0)
{
Fail("ERROR: failed to insert %s into \"%s\"\n"
char buf[256] = { 0 };
int n = -1;
- testvsp(buf, formatstr, &n);
+ testvsp(buf, _countof(buf), formatstr, &n);
if (n != param)
{
char buf[256] = { 0 };
short int n = -1;
- testvsp(buf, formatstr, &n);
+ testvsp(buf, _countof(buf), formatstr, &n);
if (n != param)
{
add_subdirectory(test2)
add_subdirectory(test3)
add_subdirectory(test4)
-add_subdirectory(test5)
add_subdirectory(test6)
add_subdirectory(test7)
add_subdirectory(test8)
return(FAIL);
checkstr = convert("hello world");
- testvswp(buf, checkstr);
+ testvswp(buf, _countof(buf), checkstr);
if (memcmp(checkstr, buf, wcslen(checkstr)*2+2) != 0)
{
{
WCHAR buf[256];
- testvswp(buf, formatstr, precision, param);
+ testvswp(buf, _countof(buf), formatstr, precision, param);
if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 &&
memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0)
{
{
WCHAR buf[256];
- testvswp(buf, formatstr, precision, param);
+ testvswp(buf, _countof(buf), formatstr, precision, param);
if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 &&
memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0)
{
{
WCHAR buf[256] = { 0 };
- testvswp(buf, formatstr, param);
+ testvswp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0)
{
{
WCHAR buf[256] = { 0 };
- testvswp(buf, formatstr, value);
+ testvswp(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0)
{
Fail("ERROR: failed to insert %s into \"%s\"\n"
+++ /dev/null
-cmake_minimum_required(VERSION 2.8.12.2)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(SOURCES
- test5.cpp
-)
-
-add_executable(paltest_vswprintf_test5
- ${SOURCES}
-)
-
-add_dependencies(paltest_vswprintf_test5 coreclrpal)
-
-target_link_libraries(paltest_vswprintf_test5
- pthread
- m
- coreclrpal
-)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*=====================================================================
-**
-** Source: test5.c
-**
-** Purpose: Test #5 for the vswprintf function.
-**
-**
-**===================================================================*/
-
-#include <palsuite.h>
-#include "../vswprintf.h"
-
-/* memcmp is used to verify the results, so this test is dependent on it. */
-/* ditto with wcslen */
-
-static void DoTest(WCHAR *formatstr, int param, WCHAR *checkstr)
-{
- WCHAR buf[256] = { 0 };
- int n = -1;
-
- testvswp(buf, formatstr, &n);
-
- if (n != param)
- {
- Fail("ERROR: Expected count parameter to resolve to %d, got %d\n",
- param, n);
- }
-
- if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0)
- {
- Fail("ERROR: Expected \"%s\" got \"%s\".\n",
- convertC(checkstr), convertC(buf));
- }
-}
-
-static void DoShortTest(WCHAR *formatstr, int param, WCHAR *checkstr)
-{
- WCHAR buf[256] = { 0 };
- short int n = -1;
-
- testvswp(buf, formatstr, &n);
-
- if (n != param)
- {
- Fail("ERROR: Expected count parameter to resolve to %d, got %d\n",
- param, n);
- }
-
- if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0)
- {
- Fail("ERROR: Expected \"%s\" got \"%s\".\n",
- convertC(checkstr), convertC(buf));
- }
-}
-
-int __cdecl main(int argc, char *argv[])
-{
- if (PAL_Initialize(argc, argv) != 0)
- return(FAIL);
-
- DoTest(convert("foo %n bar"), 4, convert("foo bar"));
- DoTest(convert("foo %#n bar"), 4, convert("foo bar"));
- DoTest(convert("foo % n bar"), 4, convert("foo bar"));
- DoTest(convert("foo %+n bar"), 4, convert("foo bar"));
- DoTest(convert("foo %-n bar"), 4, convert("foo bar"));
- DoTest(convert("foo %0n bar"), 4, convert("foo bar"));
- DoShortTest(convert("foo %hn bar"), 4, convert("foo bar"));
- DoTest(convert("foo %ln bar"), 4, convert("foo bar"));
- DoTest(convert("foo %Ln bar"), 4, convert("foo bar"));
- DoTest(convert("foo %I64n bar"), 4, convert("foo bar"));
- DoTest(convert("foo %20.3n bar"), 4, convert("foo bar"));
-
- PAL_Terminate();
- return PASS;
-}
+++ /dev/null
-# Licensed to the .NET Foundation under one or more agreements.
-# The .NET Foundation licenses this file to you under the MIT license.
-# See the LICENSE file in the project root for more information.
-
-Version = 1.0
-Section = C Runtime
-Function = vswprintf
-Name = Positive Test for vswprintf
-TYPE = DEFAULT
-EXE1 = test5
-Description
-= Tests the PAL implementation of the vswprintf function.
-= Tests vswprintf with the count specifier.
-= This test is modeled after _snwprintf.
#define __vswprintf_H__
/* These functions leaks memory like crazy. C'est la vie. */
-int testvswp(wchar_t* buf, const wchar_t* format, ...)
+int testvswp(wchar_t* buf, size_t buffSize, const wchar_t* format, ...)
{
int retVal = 0;
va_list arglist;
va_start(arglist, format);
- retVal = vswprintf(buf, format, arglist);
+ retVal = _vsnwprintf_s(buf, buffSize, _TRUNCATE, format, arglist);
va_end(arglist);
return( retVal);
{
WCHAR buf[256] = { 0 };
- testvswp(buf, formatstr, param);
+ testvswp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0)
{
{
WCHAR buf[256] = { 0 };
- testvswp(buf, formatstr, param);
+ testvswp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, wcslen(buf) * 2 + 2) != 0)
{
{
WCHAR buf[256] = { 0 };
- testvswp(buf, formatstr, param);
+ testvswp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0)
{
Fail("ERROR: failed to insert char \'%c\' (%d) into \"%s\"\n"
{
WCHAR buf[256] = { 0 };
- testvswp(buf, formatstr, param);
+ testvswp(buf, _countof(buf), formatstr, param);
if (memcmp(buf, checkstr, wcslen(buf)*2 + 2) != 0)
{
Fail("ERROR: failed to insert wide char \'%c\' (%d) into \"%s\"\n"
{
WCHAR buf[256] = { 0 };
- testvswp(buf, formatstr, value);
+ testvswp(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0)
{
Fail("ERROR: failed to insert %#x into \"%s\"\n"
{
WCHAR buf[256] = { 0 };
- testvswp(buf, formatstr, value);
+ testvswp(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr, wcslen(buf)* 2 + 2) != 0)
{
Fail("ERROR: failed to insert %s into \"%s\"\n"
{
WCHAR buf[256] = { 0 };
- testvswp(buf, formatstr, value);
+ testvswp(buf, _countof(buf), formatstr, value);
if (memcmp(buf, checkstr1, wcslen(checkstr1) + 2) != 0 &&
memcmp(buf, checkstr2, wcslen(checkstr2) + 2) != 0)
{
}
// now verify that it only used the first 3 characters of the prefix
- swprintf(wTempString, convert("%s\\%s"), wPath, wPrefix);
+ swprintf_s(wTempString, _countof(wTempString), convert("%s\\%s"), wPath, wPrefix);
if (memcmp(wTempString, wReturnedName, wcslen(wTempString)*sizeof(WCHAR)) == 0)
{
free (wPath);
c_runtime/swprintf/test19/paltest_swprintf_test19
c_runtime/swprintf/test3/paltest_swprintf_test3
c_runtime/swprintf/test4/paltest_swprintf_test4
-c_runtime/swprintf/test5/paltest_swprintf_test5
c_runtime/swprintf/test6/paltest_swprintf_test6
c_runtime/swprintf/test8/paltest_swprintf_test8
c_runtime/swprintf/test9/paltest_swprintf_test9
c_runtime/vsprintf/test2/paltest_vsprintf_test2
c_runtime/vsprintf/test3/paltest_vsprintf_test3
c_runtime/vsprintf/test4/paltest_vsprintf_test4
-c_runtime/vsprintf/test5/paltest_vsprintf_test5
c_runtime/vsprintf/test6/paltest_vsprintf_test6
c_runtime/vsprintf/test7/paltest_vsprintf_test7
c_runtime/vsprintf/test8/paltest_vsprintf_test8
c_runtime/vswprintf/test19/paltest_vswprintf_test19
c_runtime/vswprintf/test3/paltest_vswprintf_test3
c_runtime/vswprintf/test4/paltest_vswprintf_test4
-c_runtime/vswprintf/test5/paltest_vswprintf_test5
c_runtime/vswprintf/test6/paltest_vswprintf_test6
c_runtime/vswprintf/test8/paltest_vswprintf_test8
c_runtime/vswprintf/test9/paltest_vswprintf_test9
c_runtime/_stricmp/test1/paltest_stricmp_test1
c_runtime/_strlwr/test1/paltest_strlwr_test1
c_runtime/_strnicmp/test1/paltest_strnicmp_test1
-c_runtime/_vsnprintf/test1/paltest_vsnprintf_test1
-c_runtime/_vsnprintf/test10/paltest_vsnprintf_test10
-c_runtime/_vsnprintf/test11/paltest_vsnprintf_test11
-c_runtime/_vsnprintf/test12/paltest_vsnprintf_test12
-c_runtime/_vsnprintf/test13/paltest_vsnprintf_test13
-c_runtime/_vsnprintf/test14/paltest_vsnprintf_test14
-c_runtime/_vsnprintf/test15/paltest_vsnprintf_test15
-c_runtime/_vsnprintf/test16/paltest_vsnprintf_test16
-c_runtime/_vsnprintf/test17/paltest_vsnprintf_test17
-c_runtime/_vsnprintf/test18/paltest_vsnprintf_test18
-c_runtime/_vsnprintf/test19/paltest_vsnprintf_test19
-c_runtime/_vsnprintf/test2/paltest_vsnprintf_test2
-c_runtime/_vsnprintf/test3/paltest_vsnprintf_test3
-c_runtime/_vsnprintf/test4/paltest_vsnprintf_test4
-c_runtime/_vsnprintf/test5/paltest_vsnprintf_test5
-c_runtime/_vsnprintf/test6/paltest_vsnprintf_test6
-c_runtime/_vsnprintf/test7/paltest_vsnprintf_test7
-c_runtime/_vsnprintf/test8/paltest_vsnprintf_test8
-c_runtime/_vsnprintf/test9/paltest_vsnprintf_test9
+c_runtime/_vsnprintf_s/test1/paltest_vsnprintf_test1
+c_runtime/_vsnprintf_s/test10/paltest_vsnprintf_test10
+c_runtime/_vsnprintf_s/test11/paltest_vsnprintf_test11
+c_runtime/_vsnprintf_s/test12/paltest_vsnprintf_test12
+c_runtime/_vsnprintf_s/test13/paltest_vsnprintf_test13
+c_runtime/_vsnprintf_s/test14/paltest_vsnprintf_test14
+c_runtime/_vsnprintf_s/test15/paltest_vsnprintf_test15
+c_runtime/_vsnprintf_s/test16/paltest_vsnprintf_test16
+c_runtime/_vsnprintf_s/test17/paltest_vsnprintf_test17
+c_runtime/_vsnprintf_s/test18/paltest_vsnprintf_test18
+c_runtime/_vsnprintf_s/test19/paltest_vsnprintf_test19
+c_runtime/_vsnprintf_s/test2/paltest_vsnprintf_test2
+c_runtime/_vsnprintf_s/test3/paltest_vsnprintf_test3
+c_runtime/_vsnprintf_s/test4/paltest_vsnprintf_test4
+c_runtime/_vsnprintf_s/test6/paltest_vsnprintf_test6
+c_runtime/_vsnprintf_s/test7/paltest_vsnprintf_test7
+c_runtime/_vsnprintf_s/test8/paltest_vsnprintf_test8
+c_runtime/_vsnprintf_s/test9/paltest_vsnprintf_test9
c_runtime/_vsnwprintf_s/test1/paltest_vsnwprintf_test1
c_runtime/_vsnwprintf_s/test10/paltest_vsnwprintf_test10
c_runtime/_vsnwprintf_s/test11/paltest_vsnwprintf_test11
c_runtime/_stricmp/test1,1
c_runtime/_strlwr/test1,1
c_runtime/_strnicmp/test1,1
-c_runtime/_vsnprintf/test1,1
-c_runtime/_vsnprintf/test2,1
-c_runtime/_vsnprintf/test3,1
-c_runtime/_vsnprintf/test4,1
-c_runtime/_vsnprintf/test5,1
-c_runtime/_vsnprintf/test6,1
-c_runtime/_vsnprintf/test7,1
-c_runtime/_vsnprintf/test8,1
-c_runtime/_vsnprintf/test9,1
-c_runtime/_vsnprintf/test10,1
-c_runtime/_vsnprintf/test11,1
-c_runtime/_vsnprintf/test12,1
-c_runtime/_vsnprintf/test13,1
-c_runtime/_vsnprintf/test14,1
-c_runtime/_vsnprintf/test15,1
-c_runtime/_vsnprintf/test16,1
-c_runtime/_vsnprintf/test17,1
-c_runtime/_vsnprintf/test18,1
-c_runtime/_vsnprintf/test19,1
+c_runtime/_vsnprintf_s/test1,1
+c_runtime/_vsnprintf_s/test2,1
+c_runtime/_vsnprintf_s/test3,1
+c_runtime/_vsnprintf_s/test4,1
+c_runtime/_vsnprintf_s/test6,1
+c_runtime/_vsnprintf_s/test7,1
+c_runtime/_vsnprintf_s/test8,1
+c_runtime/_vsnprintf_s/test9,1
+c_runtime/_vsnprintf_s/test10,1
+c_runtime/_vsnprintf_s/test11,1
+c_runtime/_vsnprintf_s/test12,1
+c_runtime/_vsnprintf_s/test13,1
+c_runtime/_vsnprintf_s/test14,1
+c_runtime/_vsnprintf_s/test15,1
+c_runtime/_vsnprintf_s/test16,1
+c_runtime/_vsnprintf_s/test17,1
+c_runtime/_vsnprintf_s/test18,1
+c_runtime/_vsnprintf_s/test19,1
c_runtime/_vsnwprintf_s/test1,1
c_runtime/_vsnwprintf_s/test2,1
c_runtime/_vsnwprintf_s/test3,1
if (cchMax < 39)
return 0;
- return swprintf(lptsz, W("{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}"),
+ return swprintf_s(lptsz, cchMax, W("{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}"),
rguid.Data1, rguid.Data2, rguid.Data3,
rguid.Data4[0], rguid.Data4[1],
rguid.Data4[2], rguid.Data4[3],
needsPrefix = (fmt[strlen(fmt)-1] == '\n');
- int cCountWritten = _vsnprintf(&pBuffer[buflen], BUFFERSIZE-buflen, fmt, args );
+ int cCountWritten = _vsnprintf_s(&pBuffer[buflen], BUFFERSIZE-buflen, _TRUNCATE, fmt, args );
pBuffer[BUFFERSIZE-1] = 0;
if (cCountWritten < 0) {
buflen = BUFFERSIZE - 1;
else
if (errno!=0 && errno!=EBADF && errno!=ERANGE)
{
- CONSISTENCY_CHECK_MSG(FALSE, "_vsnprintf failed. Potential globalization bug.");
+ CONSISTENCY_CHECK_MSG(FALSE, "_vsnprintf_s failed. Potential globalization bug.");
ThrowHR(HRESULT_FROM_WIN32(ERROR_NO_UNICODE_TRANSLATION));
}
}
int len;
len = sprintf_s(buffer, _countof(buffer), "Mcj TID %04x: ", GetCurrentThreadId());
- len += _vsnprintf(buffer + len, _countof(buffer) - len, format, args);
+ len += _vsnprintf_s(buffer + len, _countof(buffer) - len, format, args);
len += sprintf_s(buffer + len, _countof(buffer) - len, ", (time=%d ms)\r\n", GetTickCount() - s_startTick);
OutputDebugStringA(buffer);