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
This commit is contained in:
anders_k 2015-10-30 03:55:30 +00:00
parent b54c831ff0
commit 1c1d1d5e12
12 changed files with 124 additions and 31 deletions

View file

@ -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 ;)

View file

@ -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();

View file

@ -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);

View file

@ -9,8 +9,7 @@
** Keep everything here strictly ANSI. No TCHAR style stuff.
*/
#include "netinc.h"
#include <windows.h>
#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 <intrin.h>
#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)
{

View file

@ -2,6 +2,14 @@
#include <windows.h>
#include <nsis/pluginapi.h> // 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) ||

View file

@ -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<char*>(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<char*>(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);
}

View file

@ -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<class F> 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;

View file

@ -25,16 +25,23 @@ Unicode support by Jim Park -- 08/24/2007
#include <winnt.h>
#include <nsis/pluginapi.h> // 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;

View file

@ -1,6 +1,13 @@
#include "../../Source/Platform.h"
#undef _tcsrchr // The fix for bug #1085 causes a MSVC redefinition warning when <tchar.h> 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 <windows.h>
#include <tchar.h>
#include <stdio.h>

View file

@ -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()])

View file

@ -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

View file

@ -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;