From 1c1d1d5e12247005e9f786c6f232e993833b29d7 Mon Sep 17 00:00:00 2001 From: anders_k Date: Fri, 30 Oct 2015 03:55:30 +0000 Subject: [PATCH] Fixed all VS2015 warnings except C4577 ('noexcept' used with no exception handling mode specified) git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6627 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/AdvSplash/advsplash.c | 8 ++++ Contrib/Makensisw/makensisw.cpp | 2 +- Contrib/Makensisw/utils.cpp | 10 ++--- Contrib/NSISdl/util.cpp | 19 +++++++- Contrib/UserInfo/UserInfo.c | 11 ++++- Contrib/VPatch/Source/GenPat/Checksums.cpp | 8 ++-- Contrib/VPatch/Source/GenPat/GlobalTypes.h | 50 +++++++++++++++++++--- Contrib/nsExec/nsexec.c | 24 +++++++---- Contrib/zip2exe/main.cpp | 7 +++ SConstruct | 1 + Source/Platform.h | 13 ++++++ Source/exehead/fileform.c | 2 +- 12 files changed, 124 insertions(+), 31 deletions(-) diff --git a/Contrib/AdvSplash/advsplash.c b/Contrib/AdvSplash/advsplash.c index 1d7b2260..80fab0e1 100644 --- a/Contrib/AdvSplash/advsplash.c +++ b/Contrib/AdvSplash/advsplash.c @@ -11,6 +11,14 @@ # define LWA_ALPHA 2 #endif +#if defined(_MSC_VER) && !defined(GetVersion) +#if _MSC_VER >= 1500 +FORCEINLINE DWORD NoDepr_GetVersion() { __pragma(warning(push))__pragma(warning(disable:4996)) DWORD r = GetVersion(); __pragma(warning(pop)) return r; } +#define GetVersion NoDepr_GetVersion +#endif //~ _MSC_VER >= 1500 +#endif //~ _MSC_VER + + HINSTANCE g_hInstance; #define RESOLUTION 32 // 30 fps ;) (32? I like SHR more than iDIV ;) diff --git a/Contrib/Makensisw/makensisw.cpp b/Contrib/Makensisw/makensisw.cpp index 0e0b5b87..1a2d6bda 100644 --- a/Contrib/Makensisw/makensisw.cpp +++ b/Contrib/Makensisw/makensisw.cpp @@ -267,7 +267,7 @@ INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam num = DragQueryFile((HDROP)wParam,(UINT)-1,NULL,0); if (num==1) { DragQueryFile((HDROP)wParam,0,szTmp,MAX_PATH); - if (lstrlen(szTmp)>0) { + if (szTmp[0]) { SetScript(szTmp); PushMRUFile(g_sdata.script); ResetObjects(); diff --git a/Contrib/Makensisw/utils.cpp b/Contrib/Makensisw/utils.cpp index ab35096e..b0440822 100644 --- a/Contrib/Makensisw/utils.cpp +++ b/Contrib/Makensisw/utils.cpp @@ -720,21 +720,19 @@ BOOL PopMRUFile(TCHAR* fname) void PushMRUFile(TCHAR* fname) { - int i; - DWORD rv; TCHAR full_file_name[MAX_PATH+1]; if(!fname || fname[0] == _T('\0') || fname[0] == _T('/') || fname[0] == _T('-')) { return; } - memset(full_file_name,0,sizeof(full_file_name)); - rv = GetFullPathName(fname,COUNTOF(full_file_name),full_file_name,NULL); - if (rv == 0) { + DWORD rv = GetFullPathName(fname,COUNTOF(full_file_name),full_file_name,NULL); + if (rv == 0 || rv >= COUNTOF(full_file_name)) { return; } if(IsValidFile(full_file_name)) { + int i; PopMRUFile(full_file_name); for(i = MRU_LIST_SIZE - 2; i >= 0; i--) { lstrcpy(g_mru_list[i+1], g_mru_list[i]); @@ -762,7 +760,7 @@ void BuildMRUMenus() // Remove MRU separator int seppos = n - 1; - mii.fMask = MIIM_TYPE; + mii.fMask = MIIM_TYPE, mii.cch = 0; if (GetMenuItemInfo(hMenu, seppos, TRUE, &mii)) { if (MFT_SEPARATOR & mii.fType) { DeleteMenu(hMenu, seppos, MF_BYPOSITION); diff --git a/Contrib/NSISdl/util.cpp b/Contrib/NSISdl/util.cpp index 37ac386c..7fd7c1df 100644 --- a/Contrib/NSISdl/util.cpp +++ b/Contrib/NSISdl/util.cpp @@ -9,8 +9,7 @@ ** Keep everything here strictly ANSI. No TCHAR style stuff. */ -#include "netinc.h" - +#include #include "util.h" int my_atoi(char *s) @@ -75,10 +74,26 @@ void myitoa64(__int64 i, char *buffer) *buffer = 0; } +// Visual Studio 2015 (CLv19 x86) and some older versions of CLv14 x64 will optimize +// our loop into a direct call to _memset and this fails to link because we don't use the CRT +#if defined(_MSC_VER) && _MSC_VER+0 >= 1400 +#if defined(_MSC_FULL_VER) && _MSC_FULL_VER+0 >= 140050727 +#include +#else +EXTERN_C void __stosb(BYTE*,BYTE,size_t); +#endif //~ _MSC_FULL_VER >= 140050727 +#pragma intrinsic(__stosb) +#define CRTINTRINSIC_memset(p,c,s) __stosb((BYTE*)(p),(BYTE)(c),(s)) +#endif //~ _MSC_VER + void mini_memset(void *o,char i,int l) { +#ifdef CRTINTRINSIC_memset + CRTINTRINSIC_memset(o, i, l); +#else char *oo=(char*)o; while (l-- > 0) *oo++=i; +#endif } void mini_memcpy(void *o,void*i,int l) { diff --git a/Contrib/UserInfo/UserInfo.c b/Contrib/UserInfo/UserInfo.c index 11274164..d4c46770 100644 --- a/Contrib/UserInfo/UserInfo.c +++ b/Contrib/UserInfo/UserInfo.c @@ -2,6 +2,14 @@ #include #include // nsis plugin + +#if defined(_MSC_VER) && !defined(GetVersion) +#if _MSC_VER >= 1500 +FORCEINLINE DWORD NoDepr_GetVersion() { __pragma(warning(push))__pragma(warning(disable:4996)) DWORD r = GetVersion(); __pragma(warning(pop)) return r; } +#define GetVersion NoDepr_GetVersion +#endif //~ _MSC_VER >= 1500 +#endif //~ _MSC_VER + typedef BOOL (WINAPI*CHECKTOKENMEMBERSHIP)(HANDLE TokenHandle,PSID SidToCheck,PBOOL IsMember); CHECKTOKENMEMBERSHIP _CheckTokenMembership=NULL; @@ -47,11 +55,12 @@ TCHAR* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny) TCHAR *group = NULL; HANDLE hToken = NULL; - +#ifndef _WIN64 if (GetVersion() & 0x80000000) // Not NT { return _T("Admin"); } +#endif // First we must open a handle to the access token for this thread. if (OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &hToken) || diff --git a/Contrib/VPatch/Source/GenPat/Checksums.cpp b/Contrib/VPatch/Source/GenPat/Checksums.cpp index b3b2e513..e250f6fa 100644 --- a/Contrib/VPatch/Source/GenPat/Checksums.cpp +++ b/Contrib/VPatch/Source/GenPat/Checksums.cpp @@ -36,8 +36,8 @@ void InitCRC() { int i, j; unsigned long c; for (c = i = 0; i < 256; c = ++i) { for (j = 0; j < 8; j++) { - if (c & 1) c = (c>>1) ^ 0xEDB88320; - else c >>= 1; + if (c & 1) c = (c>>1) ^ 0xEDB88320; + else c >>= 1; } CRCTable[i] = c; } @@ -56,7 +56,7 @@ crc32_t streamCRC32(bistream& data) { crc32_t crc = 0xFFFFFFFF; while(data.good()) { data.read(reinterpret_cast(block), CRCBLOCKSIZE); - read = data.gcount(); + read = (unsigned int) data.gcount(); // The cast is safe because we never read more than CRCBLOCKSIZE for (p = block; p < block + read; p++) crc = CRCTable[(crc & 0xFF) ^ *p] ^ (crc >> 8); } @@ -77,7 +77,7 @@ void streamMD5(bistream& data, md5_byte_t digest[16]) { while(data.good()) { data.read(reinterpret_cast(md5block), MD5BLOCKSIZE); - read = data.gcount(); + read = (unsigned int) data.gcount(); // The cast is safe because we never read more than MD5BLOCKSIZE md5_append(&state, md5block, read); } diff --git a/Contrib/VPatch/Source/GenPat/GlobalTypes.h b/Contrib/VPatch/Source/GenPat/GlobalTypes.h index 579592f0..1276e229 100644 --- a/Contrib/VPatch/Source/GenPat/GlobalTypes.h +++ b/Contrib/VPatch/Source/GenPat/GlobalTypes.h @@ -96,13 +96,13 @@ public: bool good() const {return ios_base::goodbit==m_state;} streamsize gcount() const {return m_LastReadCount;} - streampos tellg() const {return ftell(m_File);} + long tellg() const {return ftell(m_File);} simplebfstream& read(char*s,streamsize n) { - size_t cbio = fread(s, 1, n, m_File); + streamsize cbio = fread(s, 1, n); m_LastReadCount = cbio; - if (cbio != (size_t)n) + if (cbio != n) { m_state |= ferror(m_File) ? ios_base::badbit : (ios_base::eofbit|ios_base::failbit); } @@ -112,7 +112,7 @@ public: simplebfstream& seekg(streamoff off, ios_base::seekdir dir) { int origin = ios_base::beg==dir ? SEEK_SET : ios_base::cur==dir ? SEEK_CUR : SEEK_END; - if (fseek(m_File, off, origin)) + if (fseek(off, origin)) { // BUGBUG: Does not follow standard m_state |= ios_base::badbit|ios_base::failbit; @@ -121,16 +121,52 @@ public: } simplebfstream& seekp(streamoff off, ios_base::seekdir dir) {return seekg(off, dir);} - streampos tellp() const {return tellg();} + long tellp() const {return tellg();} simplebfstream& write(const char* s, streamsize n) { - size_t cbio = fwrite(s, 1, n, m_File); - if (cbio != (size_t)n) m_state |= ios_base::badbit; + streamsize cbio = fwrite(s, 1, n); + if (cbio != n) m_state |= ios_base::badbit; return *this; } bool operator ! () const {return fail();} +protected: + // streamsize and streamoff can be INT64 on x86 in VS2015 + template streamsize readwritehelper(void*buf, size_t itemsize, streamsize count, F func) + { + if (sizeof(streamsize) <= sizeof(size_t)) + return func(buf, itemsize, (size_t) count, m_File); + for (streamsize totc = 0;;) + { + size_t small = count > 0x7fffffff ? 0x7fffffff : (size_t) count; + size_t rv = func(((char*)buf) + totc, itemsize, small, m_File); + count -= (streamsize) rv, totc += rv; + if (rv != small) + return totc; + } + } + streamsize fread(void*buf, size_t itemsize, streamsize count) + { + return readwritehelper(buf, itemsize, count, ::fread); + } + streamsize fwrite(const void*buf, size_t itemsize, streamsize count) + { + return readwritehelper((void*) buf, itemsize, count, ::fwrite); + } + int fseek(streamoff off, int origin) + { + if (sizeof(streamoff) <= sizeof(long)) + return ::fseek(m_File, (long) off, origin); + for (;;) + { + long small = off > 0x7fffffff ? 0x7fffffff : off < -2147483647 ? -2147483647 : (long) off; + int retval = ::fseek(m_File, small, origin); + off -= small, origin = SEEK_CUR; + if (!off || retval) + return retval; + } + } }; typedef simplebfstream bistream; diff --git a/Contrib/nsExec/nsexec.c b/Contrib/nsExec/nsexec.c index a2e98059..b99d3ed8 100644 --- a/Contrib/nsExec/nsexec.c +++ b/Contrib/nsExec/nsexec.c @@ -25,16 +25,23 @@ Unicode support by Jim Park -- 08/24/2007 #include #include // nsis plugin +#if defined(_MSC_VER) && !defined(GetVersion) +#if _MSC_VER >= 1500 +FORCEINLINE DWORD NoDepr_GetVersion() { __pragma(warning(push))__pragma(warning(disable:4996)) DWORD r = GetVersion(); __pragma(warning(pop)) return r; } +#define GetVersion NoDepr_GetVersion +#endif //~ _MSC_VER >= 1500 +#endif //~ _MSC_VER + #ifndef true #define true TRUE #endif #ifndef false #define false FALSE #endif -#define LOOPTIMEOUT 100 -HWND g_hwndParent; -HWND g_hwndList; +#define LOOPTIMEOUT 100 +HWND g_hwndParent; +HWND g_hwndList; void ExecScript(BOOL log); void LogMessage(const TCHAR *pStr, BOOL bOEM); @@ -239,7 +246,7 @@ params: SECURITY_ATTRIBUTES sa={sizeof(sa),}; SECURITY_DESCRIPTOR sd={0,}; PROCESS_INFORMATION pi={0,}; - OSVERSIONINFO osv={sizeof(osv)}; + const BOOL isNT = sizeof(void*) > 4 || (GetVersion() < 0x80000000); HANDLE newstdout=0,read_stdout=0; HANDLE newstdin=0,read_stdin=0; DWORD dwRead = 1; @@ -262,15 +269,14 @@ params: szUnusedBuf = (TCHAR *)GlobalLock(hUnusedBuf); } - GetVersionEx(&osv); // Get OS info - if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) { + sa.bInheritHandle = true; + sa.lpSecurityDescriptor = NULL; + if (isNT) { InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(&sd,true,NULL,false); sa.lpSecurityDescriptor = &sd; } - else - sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = true; + if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) { lstrcpy(szRet, _T("error")); goto done; diff --git a/Contrib/zip2exe/main.cpp b/Contrib/zip2exe/main.cpp index 2c6f3bf6..13ba91ce 100644 --- a/Contrib/zip2exe/main.cpp +++ b/Contrib/zip2exe/main.cpp @@ -1,6 +1,13 @@ #include "../../Source/Platform.h" #undef _tcsrchr // The fix for bug #1085 causes a MSVC redefinition warning when is included by zlib/unzip.h -> zlib/ioapi.h. + +// Platform.h includes our custom tchar.h and +// VS2015 does not like this because we are about to pull in its tchar.h. +// As a temporary workaround we just undefine the things it disagrees with: +#undef _vstprintf +#undef _tcstok + #include #include #include diff --git a/SConstruct b/SConstruct index f3be7f26..0f42d4d2 100644 --- a/SConstruct +++ b/SConstruct @@ -448,6 +448,7 @@ def DistributeExtras(env, target, examples, docs): ###################################################################### if defenv['MSTOOLKIT']: + Import('GetOptionOrEnv') if GetOptionOrEnv('MSVC_USE_SCRIPT', '!') != '!': defenv['MSVC_USE_SCRIPT'] = GetOptionOrEnv('MSVC_USE_SCRIPT') defenv.Tool('mstoolkit', toolpath = [Dir('SCons/Tools').rdir()]) diff --git a/Source/Platform.h b/Source/Platform.h index 44f2d4e3..de19f866 100644 --- a/Source/Platform.h +++ b/Source/Platform.h @@ -1054,4 +1054,17 @@ Example: _tprintf(_T("Hello %") NPRIs _T("\n"), _T("World")); # define NPRIpN "p" #endif + +// Disable deprecated warnings (Windows SDK for Windows 8.1) +#ifdef _MSC_VER +#if _MSC_VER >= 1500 +FORCEINLINE DWORD NoDepr_GetVersion() { __pragma(warning(push))__pragma(warning(disable:4996)) DWORD r = GetVersion(); __pragma(warning(pop)) return r; } +#define GetVersion NoDepr_GetVersion +FORCEINLINE BOOL NoDepr_GetVersionExA(OSVERSIONINFOA*p) { __pragma(warning(push))__pragma(warning(disable:4996)) BOOL r = GetVersionExA(p); __pragma(warning(pop)) return r; } +#define GetVersionExA NoDepr_GetVersionExA +FORCEINLINE BOOL NoDepr_GetVersionExW(OSVERSIONINFOW*p) { __pragma(warning(push))__pragma(warning(disable:4996)) BOOL r = GetVersionExW(p); __pragma(warning(pop)) return r; } +#define GetVersionExW NoDepr_GetVersionExW +#endif //~ _MSC_VER >= 1500 +#endif //~ _MSC_VER + #endif // EOF diff --git a/Source/exehead/fileform.c b/Source/exehead/fileform.c index 8397ba80..d77252b1 100644 --- a/Source/exehead/fileform.c +++ b/Source/exehead/fileform.c @@ -334,7 +334,7 @@ const TCHAR * NSISCALL loadHeaders(int cl_flags) while (left--) { #ifdef DEBUG - if (h.length_of_header < header->blocks[left].offset) + if ((UINT_PTR) h.length_of_header < header->blocks[left].offset) return _LANG_GENERIC_ERROR; // Should never happen #endif header->blocks[left].offset += (UINT_PTR) data;