From 4b11dc566a5bbfa1378d6266525c281b028abcc8 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 10 Feb 2017 20:35:12 +0900 Subject: Imported Upstream version 1.0.0.9910 --- src/pal/src/cruntime/file.cpp | 78 --- src/pal/src/cruntime/math.cpp | 8 - src/pal/src/cruntime/printf.cpp | 82 --- src/pal/src/cruntime/printfcpp.cpp | 940 ++++----------------------------- src/pal/src/cruntime/silent_printf.cpp | 280 ---------- src/pal/src/cruntime/string.cpp | 2 +- 6 files changed, 118 insertions(+), 1272 deletions(-) (limited to 'src/pal/src/cruntime') diff --git a/src/pal/src/cruntime/file.cpp b/src/pal/src/cruntime/file.cpp index 5fe2b671f3..0eb2cea151 100644 --- a/src/pal/src/cruntime/file.cpp +++ b/src/pal/src/cruntime/file.cpp @@ -194,45 +194,6 @@ static BOOL WriteOnlyMode(FILE* pFile) } #endif //UNGETC_NOT_RETURN_EOF -/*++ -Function: - _getw - -Gets an integer from a stream. - -Return Value - -_getw returns the integer value read. A return value of EOF indicates -either an error or end of file. However, because the EOF value is also -a legitimate integer value, use feof or ferror to verify an -end-of-file or error condition. - -Parameter - -file Pointer to FILE structure - ---*/ -int -__cdecl -_getw(PAL_FILE *f) -{ - INT ret = 0; - - PERF_ENTRY(_getw); - ENTRY("_getw (f=%p)\n", f); - - _ASSERTE(f != NULL); - - CLEARERR(f); - - ret = getw( f->bsdFilePtr ); - LOGEXIT( "returning %d\n", ret ); - PERF_EXIT(_getw); - - return ret; -} - - /*++ Function: _fdopen @@ -447,45 +408,6 @@ _wfsopen( return NULL; } -/*++ -Function: - _putw - -Writes an integer to a stream. - -Return Value - -_putw returns the value written. A return value of EOF may indicate an -error. Because EOF is also a legitimate integer value, use ferror to -verify an error. - -Parameters - -c Binary integer to be output -file Pointer to FILE structure - ---*/ -int -__cdecl -_putw(int c, PAL_FILE *f) -{ - INT ret = 0; - - PERF_ENTRY(_putw); - ENTRY("_putw (c=0x%x, f=%p)\n", c, f); - - _ASSERTE(f != NULL); - - CLEARERR(f); - - ret = putw(c, f->bsdFilePtr ); - LOGEXIT( "returning %d\n", ret ); - PERF_EXIT(_putw); - - return ret; -} - - /*++ Function PAL_get_stdout. diff --git a/src/pal/src/cruntime/math.cpp b/src/pal/src/cruntime/math.cpp index 08f4192998..d53dbe7982 100644 --- a/src/pal/src/cruntime/math.cpp +++ b/src/pal/src/cruntime/math.cpp @@ -66,11 +66,7 @@ int __cdecl _finite(double x) PERF_ENTRY(_finite); ENTRY("_finite (x=%f)\n", x); -#if defined(_IA64_) && defined (_HPUX_) - ret = !isnan(x) && (x != PAL_POSINF_DBL) && (x != PAL_NEGINF_DBL); -#else ret = isfinite(x); -#endif LOGEXIT("_finite returns int %d\n", ret); PERF_EXIT(_finite); @@ -452,11 +448,7 @@ int __cdecl _finitef(float x) PERF_ENTRY(_finitef); ENTRY("_finitef (x=%f)\n", x); -#if defined(_IA64_) && defined (_HPUX_) - ret = !isnan(x) && (x != PAL_POSINF_FLT) && (x != PAL_NEGINF_FLT); -#else ret = isfinite(x); -#endif LOGEXIT("_finitef returns int %d\n", ret); PERF_EXIT(_finitef); diff --git a/src/pal/src/cruntime/printf.cpp b/src/pal/src/cruntime/printf.cpp index c437b8e39f..72c7e11bea 100644 --- a/src/pal/src/cruntime/printf.cpp +++ b/src/pal/src/cruntime/printf.cpp @@ -1363,34 +1363,6 @@ int PAL_wvsscanf(LPCWSTR Buffer, LPCWSTR Format, va_list ap) return Length; } -/*++ -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 @@ -1420,60 +1392,6 @@ PAL_swscanf( } -/*++ -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: diff --git a/src/pal/src/cruntime/printfcpp.cpp b/src/pal/src/cruntime/printfcpp.cpp index ea074a604b..0b9072102b 100644 --- a/src/pal/src/cruntime/printfcpp.cpp +++ b/src/pal/src/cruntime/printfcpp.cpp @@ -35,8 +35,9 @@ SET_DEFAULT_DEBUG_CHANNEL(CRT); 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); +static const char __nullstring[] = "(null)"; /* string to print on null ptr */ +static const WCHAR __wnullstring[] = W("(null)"); /* string to print on null ptr */ + 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); @@ -865,7 +866,7 @@ Parameters: - padding style flags (PRINTF_FORMAT_FLAGS) *******************************************************************************/ -INT Internal_AddPaddingVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, LPSTR In, +INT Internal_AddPaddingVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, LPCSTR In, INT Padding, INT Flags) { LPSTR Out; @@ -1051,49 +1052,6 @@ static INT Internal_AddPaddingVfwprintf(CPalThread *pthrCurrent, PAL_FILE *strea return Written; } -/******************************************************************************* -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 @@ -1132,31 +1090,17 @@ int __cdecl PAL_vfwprintf(PAL_FILE *stream, const wchar_16 *format, va_list ap) } // 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 % format string */ LPCWSTR Fmt = format; - LPWSTR TempWStr = NULL; + LPCWSTR TempWStr = NULL; + LPWSTR AllocedTempWStr = NULL; LPWSTR WorkingWStr = NULL; WCHAR TempWChar[2]; INT Flags; @@ -1165,7 +1109,6 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for INT Prefix; INT Type; INT TempInt; - BOOL WStrWasMalloced = FALSE; int mbtowcResult; int written=0; int paddingReturnValue; @@ -1193,7 +1136,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for (Type == PFF_TYPE_STRING || Type == PFF_TYPE_WSTRING)) || (Type == PFF_TYPE_WSTRING && (Flags & PFF_ZERO) != 0)) { - WStrWasMalloced = FALSE; + AllocedTempWStr = NULL; if (WIDTH_STAR == Width) { @@ -1222,37 +1165,50 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for else { /* %lS assumes a LPSTR argument. */ - LPSTR s = va_arg(ap, LPSTR ); - UINT Length = 0; - Length = MultiByteToWideChar( CP_ACP, 0, s, -1, NULL, 0 ); - if ( Length != 0 ) + LPCSTR s = va_arg(ap, LPSTR ); + if (s == NULL) { - TempWStr = - (LPWSTR)InternalMalloc( (Length) * sizeof( WCHAR ) ); - if ( TempWStr ) + TempWStr = NULL; + } + else + { + UINT Length = 0; + Length = MultiByteToWideChar( CP_ACP, 0, s, -1, NULL, 0 ); + if ( Length != 0 ) { - WStrWasMalloced = TRUE; - MultiByteToWideChar( CP_ACP, 0, s, -1, - TempWStr, Length ); + AllocedTempWStr = + (LPWSTR)InternalMalloc( (Length) * sizeof( WCHAR ) ); + + if ( AllocedTempWStr ) + { + MultiByteToWideChar( CP_ACP, 0, s, -1, + AllocedTempWStr, Length ); + TempWStr = AllocedTempWStr; + } + else + { + ERROR( "InternalMalloc failed.\n" ); + LOGEXIT("vfwprintf returns int -1\n"); + PERF_EXIT(vfwprintf); + va_end(ap); + return -1; + } } else { - ERROR( "InternalMalloc failed.\n" ); + ASSERT( "Unable to convert from multibyte " + " to wide char.\n" ); LOGEXIT("vfwprintf returns int -1\n"); PERF_EXIT(vfwprintf); va_end(ap); return -1; } } - else - { - ASSERT( "Unable to convert from multibyte " - " to wide char.\n" ); - LOGEXIT("vfwprintf returns int -1\n"); - PERF_EXIT(vfwprintf); - va_end(ap); - return -1; - } + } + + if (TempWStr == NULL) + { + TempWStr = __wnullstring; } INT Length = PAL_wcslen(TempWStr); @@ -1263,10 +1219,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for LOGEXIT("vfwprintf returns int -1\n"); PERF_EXIT(vfwprintf); pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY); - if (WStrWasMalloced) - { - free(TempWStr); - } + free(AllocedTempWStr); va_end(ap); return -1; } @@ -1281,10 +1234,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for if (wcsncpy_s(WorkingWStr, (Length + 1), TempWStr, Precision+1) != SAFECRT_SUCCESS) { ERROR("Internal_AddPaddingVfwprintf failed\n"); - if (WStrWasMalloced) - { - free(TempWStr); - } + free(AllocedTempWStr); free(WorkingWStr); LOGEXIT("wcsncpy_s failed!\n"); PERF_EXIT(vfwprintf); @@ -1310,10 +1260,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for if (paddingReturnValue == -1) { ERROR("Internal_AddPaddingVfwprintf failed\n"); - if (WStrWasMalloced) - { - free(TempWStr); - } + free(AllocedTempWStr); free(WorkingWStr); LOGEXIT("vfwprintf returns int -1\n"); PERF_EXIT(vfwprintf); @@ -1323,10 +1270,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for written += paddingReturnValue; free(WorkingWStr); - if (WStrWasMalloced) - { - free(TempWStr); - } + free(AllocedTempWStr); } else if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_CHAR) { @@ -1466,7 +1410,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for 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); @@ -1484,7 +1428,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for 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); } @@ -1581,13 +1525,11 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for return (written); } -int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Format, va_list aparg) +int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format, va_list aparg) { - BOOL BufferRanOut = FALSE; CHAR TempBuff[1024]; /* used to hold a single % format string */ - LPSTR BufferPtr = Buffer; - LPCSTR Fmt = Format; - LPWSTR TempWStr; + LPCSTR Fmt = format; + LPCWSTR TempWStr; LPSTR TempStr; WCHAR TempWChar; INT Flags; @@ -1598,21 +1540,20 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo INT Length; INT TempInt; int wctombResult; + int written = 0; + int paddingReturnValue; va_list ap; + PERF_ENTRY(vfprintf); + va_copy(ap, aparg); - + while (*Fmt) { - if (BufferRanOut || (BufferPtr - Buffer) >= static_cast(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 (*Fmt == '%' && + TRUE == Internal_ExtractFormatA(pthrCurrent, &Fmt, TempBuff, &Flags, + &Width, &Precision, + &Prefix, &Type)) { if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_STRING) { @@ -1637,20 +1578,26 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo } TempWStr = va_arg(ap, LPWSTR); + if (TempWStr == NULL)\ + { + TempWStr = __wnullstring; + } Length = WideCharToMultiByte(CP_ACP, 0, TempWStr, -1, 0, 0, 0, 0); if (!Length) - { + { ASSERT("WideCharToMultiByte failed. Error is %d\n", - GetLastError()); + GetLastError()); + PERF_EXIT(vfprintf); va_end(ap); return -1; } TempStr = (LPSTR) InternalMalloc(Length); if (!TempStr) - { + { ERROR("InternalMalloc failed\n"); pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY); + PERF_EXIT(vfprintf); va_end(ap); return -1; } @@ -1670,6 +1617,7 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo ASSERT("WideCharToMultiByte failed. Error is %d\n", GetLastError()); free(TempStr); + PERF_EXIT(vfprintf); va_end(ap); return -1; } @@ -1682,10 +1630,11 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo wctombResult = WideCharToMultiByte(CP_ACP, 0, TempWStr, -1, TempStr, Length, 0, 0); if (!wctombResult) - { + { ASSERT("WideCharToMultiByte failed. Error is %d\n", GetLastError()); free(TempStr); + PERF_EXIT(vfprintf); va_end(ap); return -1; } @@ -1693,18 +1642,24 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo } /* do the padding (if needed)*/ - BufferRanOut = !Internal_AddPaddingA(&BufferPtr, - Count - (BufferPtr - Buffer), - TempStr, - Width - Length, - Flags); + paddingReturnValue = + Internal_AddPaddingVfprintf(pthrCurrent, stream, TempStr, + Width - Length, Flags); + if (-1 == paddingReturnValue) + { + ERROR("Internal_AddPaddingVfprintf failed\n"); + free(TempStr); + PERF_EXIT(vfprintf); + va_end(ap); + return -1; + } + written += paddingReturnValue; free(TempStr); } else if (Prefix == PFF_PREFIX_LONG && Type == PFF_TYPE_CHAR) { CHAR TempBuffer[5]; - if (WIDTH_STAR == Width || WIDTH_INVALID == Width) { @@ -1717,26 +1672,33 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo /* 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()); + PERF_EXIT(vfprintf); va_end(ap); return -1; } TempBuffer[Length] = 0; /* do the padding (if needed)*/ - BufferRanOut = !Internal_AddPaddingA(&BufferPtr, - Count - (BufferPtr - Buffer), - TempBuffer, - Width - Length, - Flags); + paddingReturnValue = + Internal_AddPaddingVfprintf(pthrCurrent, stream, TempBuffer, + Width - Length, Flags); + if (-1 == paddingReturnValue) + { + ERROR("Internal_AddPaddingVfprintf failed\n"); + PERF_EXIT(vfprintf); + va_end(ap); + return -1; + } + written += paddingReturnValue; } /* this places the number of bytes written to the buffer in the @@ -1754,716 +1716,48 @@ int CoreVsnprintf(CPalThread *pthrCurrent, LPSTR Buffer, size_t Count, LPCSTR Fo if (Prefix == PFF_PREFIX_SHORT) { - *(va_arg(ap, short *)) = BufferPtr - Buffer; + *(va_arg(ap, short *)) = written; } else { - *(va_arg(ap, LPLONG)) = BufferPtr - Buffer; + *(va_arg(ap, LPLONG)) = written; } } else if (Type == PFF_TYPE_CHAR && (Flags & PFF_ZERO) != 0) { - // Some versions of sprintf don't support 0-padded chars, + // Some versions of fprintf 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); + paddingReturnValue = Internal_AddPaddingVfprintf( + pthrCurrent, + stream, + ch, + Width - Length, + Flags); + if (-1 == paddingReturnValue) + { + ERROR("Internal_AddPaddingVfprintf failed\n"); + PERF_EXIT(vfprintf); + va_end(ap); + return -1; + } + written += paddingReturnValue; } else if (Type == PFF_TYPE_STRING && (Flags & PFF_ZERO) != 0) { - // Some versions of sprintf don't support 0-padded strings, + // Some versions of fprintf don't support 0-padded strings, // so we handle them here. - char *tempStr; + const 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(TempInt) >= TempCount) /* buffer not long enough */ - { - BufferPtr += TempCount; - BufferRanOut = TRUE; - } - else - { - BufferPtr += TempInt; - } - } - } - else - { - *BufferPtr++ = *Fmt++; /* copy regular chars into buffer */ - } - } - - if (static_cast(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 % 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(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 + if (tempStr == NULL) { - // %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; - } - + tempStr = __nullstring; } - - 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(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(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 % format string */ - 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; - int written = 0; - int paddingReturnValue; - va_list ap; - - PERF_ENTRY(vfprintf); - - va_copy(ap, aparg); - - while (*Fmt) - { - 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()); - PERF_EXIT(vfprintf); - va_end(ap); - return -1; - } - TempStr = (LPSTR) InternalMalloc(Length); - if (!TempStr) - { - ERROR("InternalMalloc failed\n"); - pthrCurrent->SetLastError(ERROR_NOT_ENOUGH_MEMORY); - PERF_EXIT(vfprintf); - 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); - PERF_EXIT(vfprintf); - 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); - PERF_EXIT(vfprintf); - va_end(ap); - return -1; - } - --Length; /* exclude null char */ - } - - /* do the padding (if needed)*/ - paddingReturnValue = - Internal_AddPaddingVfprintf(pthrCurrent, stream, TempStr, - Width - Length, Flags); - if (-1 == paddingReturnValue) - { - ERROR("Internal_AddPaddingVfprintf failed\n"); - free(TempStr); - PERF_EXIT(vfprintf); - va_end(ap); - return -1; - } - written += paddingReturnValue; - - 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()); - PERF_EXIT(vfprintf); - va_end(ap); - return -1; - } - TempBuffer[Length] = 0; - - /* do the padding (if needed)*/ - paddingReturnValue = - Internal_AddPaddingVfprintf(pthrCurrent, stream, TempBuffer, - Width - Length, Flags); - if (-1 == paddingReturnValue) - { - ERROR("Internal_AddPaddingVfprintf failed\n"); - PERF_EXIT(vfprintf); - va_end(ap); - return -1; - } - written += paddingReturnValue; - - } - /* 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 *)) = written; - } - else - { - *(va_arg(ap, LPLONG)) = written; - } - } - else if (Type == PFF_TYPE_CHAR && (Flags & PFF_ZERO) != 0) - { - // Some versions of fprintf 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; - paddingReturnValue = Internal_AddPaddingVfprintf( - pthrCurrent, - stream, - ch, - Width - Length, - Flags); - if (-1 == paddingReturnValue) - { - ERROR("Internal_AddPaddingVfprintf failed\n"); - PERF_EXIT(vfprintf); - va_end(ap); - return -1; - } - written += paddingReturnValue; - } - else if (Type == PFF_TYPE_STRING && (Flags & PFF_ZERO) != 0) - { - // Some versions of fprintf don't support 0-padded strings, - // so we handle them here. - char *tempStr; - - tempStr = va_arg(ap, char *); Length = strlen(tempStr); paddingReturnValue = Internal_AddPaddingVfprintf( pthrCurrent, diff --git a/src/pal/src/cruntime/silent_printf.cpp b/src/pal/src/cruntime/silent_printf.cpp index 1d10963973..4047c7e199 100644 --- a/src/pal/src/cruntime/silent_printf.cpp +++ b/src/pal/src/cruntime/silent_printf.cpp @@ -40,286 +40,6 @@ static INT Silent_AddPaddingVfprintf(PAL_FILE *stream, LPSTR In, INT Padding, 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 % 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(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) diff --git a/src/pal/src/cruntime/string.cpp b/src/pal/src/cruntime/string.cpp index abe6d136f0..2abce6fd8f 100644 --- a/src/pal/src/cruntime/string.cpp +++ b/src/pal/src/cruntime/string.cpp @@ -278,7 +278,7 @@ PAL_atol(const char *szNumber) PERF_ENTRY(atol); ENTRY("atol (szNumber=%p (%s))\n", - szNumber?szNumber:"NULL" + szNumber, szNumber?szNumber:"NULL" ); lResult = atol(szNumber); -- cgit v1.2.3