* Try to avoid invalid parameter debug warning in newer versions of MSVCRT.dll when calling _vsnwprintf as a _vscwprintf replacement

* _wtof does not exist in MSVCRT.dll on Win2000, use our internal version when building with MinGW/MSVC6 or MSVC /MD


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6630 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2015-11-01 17:11:53 +00:00
parent 7b814407a3
commit 650ebca347
2 changed files with 13 additions and 8 deletions

View file

@ -96,10 +96,10 @@ typedef wchar_t TCHAR, _TUCHAR;
#define _tcstoi64 _wcstoi64
#define _tcstol wcstol
#define _tcstoul wcstoul
#if !defined(_WIN32) || (defined(_MSC_VER) && (_MSC_VER<=1200))
# define _tstof my_wtof
#if !defined(_WIN32) || !defined(_MSC_VER) || (defined(_MSC_VER) && ((_MSC_VER<=1200) || defined(_DLL))) // _wtof does not exist in older versions of MSVCRT.dll
# define _tstof my_wtof
#else
# define _tstof _wtof
# define _tstof _wtof
#endif
#define _tstoi _wtoi
#define _tstoi64 _wtoi64

View file

@ -776,13 +776,17 @@ void RawTStrToASCII(const TCHAR*in,char*out,UINT maxcch)
size_t ExpandoStrFmtVaList(wchar_t*Stack, size_t cchStack, wchar_t**ppMalloc, const wchar_t*FmtStr, va_list Args)
{
#ifdef _WIN32
static size_t qlen = INT_MAX;
// For _vsnwprintf, the \0 terminator is not part of the input size
# if _MSC_VER < 1310
const bool have__vscwprintf = false;
# define ExpandoStrFmtVaList_vsnwprintf(d,c,f,v) _vsnwprintf((d),(c)?(c)-1:0,(f),(v)) // Allow INT_MAX hack on MinGW and older versions of VC that don't have _vscwprintf
# else
const bool have__vscwprintf = true;
# define ExpandoStrFmtVaList_vsnwprintf(d,c,f,v) ( INT_MAX==(c) ? _vscwprintf((f),(v)) : _vsnwprintf((d),(c)?(c)-1:0,(f),(v)) )
# endif
#else
const size_t qlen = INT_MAX;
# define ExpandoStrFmtVaList_vsnwprintf vswprintf
#endif
#if defined(_ISOC99_SOURCE) || _POSIX_C_SOURCE >= 200112L
@ -792,10 +796,11 @@ size_t ExpandoStrFmtVaList(wchar_t*Stack, size_t cchStack, wchar_t**ppMalloc, co
if (!testedsizecalc)
{
#ifdef _WIN32
size_t cch = ExpandoStrFmtVaList_vsnwprintf(0, INT_MAX, L"333", Args);
int cch = have__vscwprintf ? 0 : ExpandoStrFmtVaList_vsnwprintf(0, qlen = 0, L"333", Args);
if (cch != 3) cch = ExpandoStrFmtVaList_vsnwprintf(0, qlen = INT_MAX, L"333", Args); // Is this actually necessary? Just set qlen = INT_MAX if have__vscwprintf?
#else
wchar_t testbuf[1+1];
size_t cch = ExpandoStrFmtVaList_vsnwprintf(testbuf, COUNTOF(testbuf), L"333", Args);
wchar_t testbuf[1+!0];
int cch = ExpandoStrFmtVaList_vsnwprintf(testbuf, COUNTOF(testbuf), L"333", Args);
#endif
testedsizecalc = (3 == cch) + 1;
}
@ -810,12 +815,12 @@ size_t ExpandoStrFmtVaList(wchar_t*Stack, size_t cchStack, wchar_t**ppMalloc, co
for(;;)
{
cch = ExpandoStrFmtVaList_vsnwprintf(dest, cchAvail, FmtStr, Args);
if ((size_t)-1 == cch)
if ((int)cch < 0)
{
cch = 0;
if (cansizecalc) break; // vswprintf error, abort!
if (msvcbackdoor)
cchAvail = ExpandoStrFmtVaList_vsnwprintf(0, INT_MAX, FmtStr, Args) + 1;
cchAvail = ExpandoStrFmtVaList_vsnwprintf(0, qlen, FmtStr, Args) + 1;
else
cchAvail = 4 * STD_MAX(cchAvail, (size_t)500);
}