diff --git a/Contrib/BgImage/BgImage.cpp b/Contrib/BgImage/BgImage.cpp index 51127a8d..00c16aa9 100644 --- a/Contrib/BgImage/BgImage.cpp +++ b/Contrib/BgImage/BgImage.cpp @@ -131,7 +131,7 @@ NSISFunc(SetBg) { hWndImage = CreateWindowEx( WS_EX_TOOLWINDOW, - (LPTSTR)(DWORD)atomClass, + (LPTSTR)(UINT_PTR)atomClass, 0, WS_CLIPSIBLINGS|WS_POPUP, 0, @@ -293,7 +293,7 @@ NSISFunc(AddText) { lstrcpy(newImg->szText, szTemp); popstring(szTemp); - newImg->hFont = (HFONT)myatoi(szTemp); + newImg->hFont = (HFONT) nsishelper_str_to_ptr(szTemp); newImg->cTextColor = GetColor(); GetXY(LPPOINT(&newImg->rPos)); diff --git a/Contrib/InstallOptions/InstallerOptions.cpp b/Contrib/InstallOptions/InstallerOptions.cpp index 7534b057..9918c6e9 100644 --- a/Contrib/InstallOptions/InstallerOptions.cpp +++ b/Contrib/InstallOptions/InstallerOptions.cpp @@ -564,7 +564,7 @@ int WINAPI ReadSettings(void) { pField->nMaxLength = myGetProfileInt(_T("MaxLen"), 0); // Text color for LINK control, default is the system default link color - pField->hImage = (HANDLE)myGetProfileInt(_T("TxtColor"), GetLinkColor()); + pField->hImage = (HANDLE)(UINT_PTR) myGetProfileInt(_T("TxtColor"), GetLinkColor()); pField->nControlID = 1200 + nIdx; if (pField->nType == FIELD_FILEREQUEST || pField->nType == FIELD_DIRREQUEST) @@ -788,7 +788,7 @@ INT_PTR CALLBACK cfgDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara { // Get TxtColor unless the user has set another using SetCtlColors if (!GetWindowLongPtr(lpdis->hwndItem, GWLP_USERDATA)) - SetTextColor(lpdis->hDC, (COLORREF) pField->hImage); + SetTextColor(lpdis->hDC, (COLORREF)(INT_PTR) pField->hImage); // Draw the text DrawText(lpdis->hDC, pField->pszText, -1, &rc, DT_CENTER | DT_VCENTER | DT_WORDBREAK | (bRTL ? DT_RTLREADING : 0)); @@ -1212,7 +1212,7 @@ int WINAPI createCfgDlg() rect.right - rect.left, rect.bottom - rect.top, hConfigWindow, - (HMENU)pField->nControlID, + (HMENU)(UINT_PTR) pField->nControlID, m_hInstance, NULL ); diff --git a/Contrib/Library/RegTool/RegTool.c b/Contrib/Library/RegTool/RegTool.c index f40b6c49..7e4e38ae 100644 --- a/Contrib/Library/RegTool/RegTool.c +++ b/Contrib/Library/RegTool/RegTool.c @@ -13,7 +13,7 @@ void RegFile(TCHAR cmd, TCHAR *file, int x64); void RegDll(TCHAR *file); void RegTypeLib(TCHAR *file); -void DeleteFileOnReboot(TCHAR *pszFile); +BOOL DeleteFileOnReboot(TCHAR *pszFile); NSIS_ENTRYPOINT_GUINOCRT EXTERN_C void NSISWinMainNOCRT() @@ -367,9 +367,9 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName) } #endif -void DeleteFileOnReboot(TCHAR *pszFile) +BOOL DeleteFileOnReboot(TCHAR *pszFile) { - BOOL fOk = 0; + BOOL fOk = FALSE; HMODULE hLib=GetModuleHandle(_T("KERNEL32.dll")); if (hLib) { @@ -385,6 +385,8 @@ void DeleteFileOnReboot(TCHAR *pszFile) if (!fOk) { RenameViaWininit(pszFile, NULL); + fOk = TRUE; // BUGBUG: We just pretend everything is OK, nobody checks our return value anyway } #endif + return fOk; } diff --git a/Contrib/Makensisw/utils.cpp b/Contrib/Makensisw/utils.cpp index 2564e86b..10b14d70 100644 --- a/Contrib/Makensisw/utils.cpp +++ b/Contrib/Makensisw/utils.cpp @@ -683,8 +683,8 @@ void ShowDocs() { path=_tcsrchr(pathf,_T('\\')); if(path!=NULL) *path=0; lstrcat(pathf,LOCALDOCS); - if ((int)ShellExecute(g_sdata.hwnd,_T("open"),pathf,NULL,NULL,SW_SHOWNORMAL)<=32) - ShellExecuteA(g_sdata.hwnd,"open",DOCPATH,NULL,NULL,SW_SHOWNORMAL); + if ((int)(INT_PTR) ShellExecute(g_sdata.hwnd,_T("open"),pathf,NULL,NULL,SW_SHOWNORMAL) <= 32) + ShellExecuteA(g_sdata.hwnd,"open",DOCPATH,NULL,NULL,SW_SHOWNORMAL); } TCHAR* BuildSymbols() diff --git a/Contrib/Math/Source/Math.c b/Contrib/Math/Source/Math.c index da39dedc..a77762de 100644 --- a/Contrib/Math/Source/Math.c +++ b/Contrib/Math/Source/Math.c @@ -11,6 +11,8 @@ extern "C" int _fltused; int _fltused = 1; #endif +#define EIPtrToInt(pEI) ( (int) (INT_PTR) (pEI) ) // Make GCC (64-bit) happy. BUGBUG64: Somebody should verify that this truncation is OK + ExpressionItem *stack; int UserVarsCount, UserFuncsCount; @@ -28,8 +30,8 @@ void PlaceNewItem(TCHAR *&vb, ParseInfo *pi, int precedence) PlaceVariable(vb, pi); if (pi->item == NULL) return; - while ((pi->OpsStack) && ((((int) pi->OpsStack->param2) < precedence) - || ((((int)pi->OpsStack->param2) == precedence) + while ((pi->OpsStack) && (((EIPtrToInt(pi->OpsStack->param2)) < precedence) + || (((EIPtrToInt(pi->OpsStack->param2)) == precedence) && (precedence != OPERATOR_SET_PRECEDENCE)))) { // second operand for our operator @@ -300,7 +302,7 @@ void PlaceOp(TCHAR *&vb, int type, int precedence, ParseInfo *pi) // uniary pre op ExpressionItem *item = AllocItem(); item->type = type; - item->param2 = (EIPARAM) precedence; + item->param2 = (EIPARAM) (INT_PTR) precedence; item->next = pi->OpsStack; pi->OpsStack = item; } @@ -323,7 +325,7 @@ void PlaceOp(TCHAR *&vb, int type, int precedence, ParseInfo *pi) } else { // binary operator - item->param2 = (EIPARAM) precedence; + item->param2 = (EIPARAM) (INT_PTR) precedence; item->next = pi->OpsStack; pi->OpsStack = item; } @@ -857,7 +859,7 @@ void SaveResult(ExpressionItem *var, ExpressionItem *result) break; case ITV_ARRITEM: { - ExpressionItem *&ei = ((ArrayDesc*)(var->param1))->array[(int)var->param2]; + ExpressionItem *&ei = ((ArrayDesc*)(var->param1))->array[(UINT_PTR)(var->param2)]; CleanupItems(ei); ei = CopyItem(result); } @@ -880,9 +882,9 @@ void SaveResult(ExpressionItem *var, ExpressionItem *result) } } -void RunAndGetConst(int from, ExpressionItem* &result, int type) +void RunAndGetConst(ExpressionItem* from, ExpressionItem* &result, int type) { - RunTree(*((ExpressionItem**)&(from)), result, type | RTO_NEEDCONST); + RunTree(from, result, type | RTO_NEEDCONST); ItemToType(result, type); } @@ -930,7 +932,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) case ITV_ARRITEM: { // array item - ExpressionItem *ei = ((ArrayDesc*)(item->param1))->array[(int)item->param2]; + ExpressionItem *ei = ((ArrayDesc*)(item->param1))->array[(UINT_PTR)(item->param2)]; if (ei) result = CopyItem(ei); else @@ -1115,7 +1117,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) int ir = -666; TCHAR *i1 = (item1)?((TCHAR*)item1->param1):(NULL); TCHAR *i2 = (item2)?((TCHAR*)item2->param1):(NULL); - int sc = (i1 && i2)?(lstrcmp(i1, i2)):((i1)?(1):((i2)?(-1):(0))); + int sc = (i1 && i2)?(lstrcmp(i1, i2)):((i1)?(1):((i2)?(-1):(0))); switch (subtype) { @@ -1176,7 +1178,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) } while (true) { - RunAndGetConst((int) ifbr, result, ITC_INT); + RunAndGetConst((ifbr), result, ITC_INT); if (ifmode) { // we need then or else branch? @@ -1260,20 +1262,21 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) CleanupItems(si); CleanupItems(var); } else if (subtype == ITF_TYPE) { - int newtype = (int) MathFunctions[ioptions].fptr; + INT_PTR newtype = (INT_PTR) MathFunctions[ioptions].fptr; if (newtype < ITC_UNKNOWN) { // get as possibly close to ready expression - RunAndGetConst((int)item->param1, result, newtype); + int truncatednewtype = (int) newtype; // BUGBUG64: Make sure this is safe for 64-bit, meaning, can newtype be < INT_MIN? + RunAndGetConst((item->param1), result, truncatednewtype); if (ioptions == ITFT_CARRAY_ID) CopyArray(result); } else if (newtype == FTT_FLOATF) { // float format function ExpressionItem *arg1, *arg2; - RunAndGetConst((int)item->param1, arg1, ITC_FLOAT); + RunAndGetConst((item->param1), arg1, ITC_FLOAT); double value = *((double*)&(arg1->param1)); - RunAndGetConst((int)item->param2, arg2, ITC_INT); + RunAndGetConst((item->param2), arg2, ITC_INT); int format = (int) *((__int64*)&(arg2->param1)); result = AllocItem(); @@ -1331,7 +1334,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) } else { // oops :-o function call :) - RunAndGetConst((int)item->param1, result, ITC_FLOAT); + RunAndGetConst((item->param1), result, ITC_FLOAT); double &value = *((double*)&(result->param1)); if (subtype == ITF_MATH1) { @@ -1365,7 +1368,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) { // normal 2-arg math function ExpressionItem *arg2; - RunAndGetConst((int)item->param2, arg2, ITC_FLOAT); + RunAndGetConst((item->param2), arg2, ITC_FLOAT); double value2 = *((double*)&(arg2->param1)); value = ((Math2FuncPtr)(MathFunctions[ioptions].fptr))(value, value2); CleanupItems(arg2); @@ -1388,7 +1391,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) if ((*((ExpressionItem **) &(item->param2)))->type != IT_EXPRESSION) { // one index - user need a char - RunAndGetConst((int)item->param2, index, ITC_INT); + RunAndGetConst((item->param2), index, ITC_INT); int pos = (int) *((__int64*)&(index->param1)); if (pos < 0) pos += len; // -index - means from end @@ -1408,7 +1411,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) if ((*((ExpressionItem **) &(item->param2)))->param1 == 0) index = AllocItem(); else - RunAndGetConst((int)(*((ExpressionItem **) &(item->param2)))->param1, index, ITC_INT); + RunAndGetConst(((*((ExpressionItem **) &(item->param2)))->param1), index, ITC_INT); if ((*((ExpressionItem **) &(item->param2)))->next->param1 == 0) { // if second index is skipped -> -1 (till last char) @@ -1416,7 +1419,7 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) *((__int64*)&(index2->param1)) = -1; } else - RunAndGetConst((int)(*((ExpressionItem **) &(item->param2)))->next->param1, index2, ITC_INT); + RunAndGetConst(((*((ExpressionItem **) &(item->param2)))->next->param1), index2, ITC_INT); // ok, we've got two indexes int pos1 = (int) *((__int64*)&(index->param1)); @@ -1445,16 +1448,16 @@ void RunTree(ExpressionItem *from, ExpressionItem* &result, int options) } else { // argument is array - RunAndGetConst((int)item->param2, index, ITC_INT); + RunAndGetConst((item->param2), index, ITC_INT); // convert array pointer to array item pointer aritem->type = IT_VARIABLE | ITV_ARRITEM; aritem->param2 = (EIPARAM) *((__int64*)&(index->param1)); ArrayDesc *ad = (ArrayDesc*)aritem->param1; - if (((int)aritem->param2) >= ad->count) + if ((EIPtrToInt(aritem->param2)) >= ad->count) { - ad->count = ((int)aritem->param2)+1; + ad->count = (EIPtrToInt(aritem->param2))+1; while (ad->count > ad->size) { // resize array diff --git a/Contrib/NSISdl/netinc.h b/Contrib/NSISdl/netinc.h index 8360ef50..bb8a3893 100644 --- a/Contrib/NSISdl/netinc.h +++ b/Contrib/NSISdl/netinc.h @@ -17,8 +17,12 @@ #define strcasecmp(x,y) stricmp(x,y) #define ERRNO (WSAGetLastError()) #define SET_SOCK_BLOCK(s,block) { unsigned long __i=block?0:1; ioctlsocket(s,FIONBIO,&__i); } +#ifndef EWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK +#endif +#ifndef EINPROGRESS #define EINPROGRESS WSAEWOULDBLOCK +#endif #define memset mini_memset #define memcpy mini_memcpy // Jim Park: For Unicode support, we need to distinguish whether we are working on diff --git a/Contrib/System/SConscript b/Contrib/System/SConscript index 676096b0..35cdc524 100644 --- a/Contrib/System/SConscript +++ b/Contrib/System/SConscript @@ -29,34 +29,30 @@ Import('BuildPlugin env') defs = ['SYSTEM_EXPORTS'] msvc = 'msvc' in env['TOOLS'] or 'mstoolkit' in env['TOOLS'] -if env['TARGET_ARCH'] != 'amd64' or msvc: # BUGBUG: Call-amd64.S is missing GAS macros - srcsuff = '' - if env['TARGET_ARCH'] != 'x86': - srcsuff = '-' + env['TARGET_ARCH'] - defs += ['SYSTEM_NOCALLBACKS'] # BUGBUG: Remove this when CallBack() is implemented - if msvc: # BUGBUG: Remove this when GAS is fixed - defs += ['SYSTEM_PARTIALCALLSUPPORT'] - filename = 'Call' + srcsuff +srcsuff = '' +if env['TARGET_ARCH'] != 'x86': + srcsuff = '-' + env['TARGET_ARCH'] + defs += ['SYSTEM_NOCALLBACKS'] # BUGBUG: Remove this when CallBack() is implemented + defs += ['SYSTEM_PARTIALCALLSUPPORT'] +filename = 'Call' + srcsuff - src_ascpp = """ - #if 0 /* a C style comment */ - ERROR: assembler-with-cpp required! - #else - .end - #endif - """ - conf = env.Configure() - if conf.TryCompile('END', '.S'): - files += ['Source/'+filename+'.S'] - elif (not msvc) and conf.TryCompile(src_ascpp, '.S'): - files += ['Source/'+filename+'CPP.S'] - elif (not msvc) and conf.TryCompile(src_ascpp, '.sx'): - files += ['Source/'+filename+'CPP.sx'] - else: - print 'WARNING: System.dll: unable to find assembler for '+filename+'.S' - conf.Finish() +src_ascpp = """ + #if 0 /* a C style comment */ + ERROR: assembler-with-cpp required! + #else + .end + #endif +""" +conf = env.Configure() +if conf.TryCompile('END', '.S'): + files += ['Source/'+filename+'.S'] +elif (not msvc) and conf.TryCompile(src_ascpp, '.S'): + files += ['Source/'+filename+'CPP.S'] +elif (not msvc) and conf.TryCompile(src_ascpp, '.sx'): + files += ['Source/'+filename+'CPP.sx'] else: - print 'WARNING: System.dll: missing Win64 code, dynamic function calls not supported' + print 'WARNING: System.dll: unable to find assembler for '+filename+'.S' +conf.Finish() BuildPlugin( target, diff --git a/Contrib/System/Source/Call-amd64.S b/Contrib/System/Source/Call-amd64.S index 2dbe3806..969be2ab 100644 --- a/Contrib/System/Source/Call-amd64.S +++ b/Contrib/System/Source/Call-amd64.S @@ -15,6 +15,9 @@ ;# MASM: ;# ml64.exe /c Call-amd64.S ;# +;# Notes: +;# * MASM does not accept 0x* constants and GAS does not accept *h constants in Intel mode, must use decimal! +;# ; .if 0 ;# MASM @@ -34,6 +37,7 @@ IF 0 ; .else ;# GNU .intel_syntax noprefix +.set __GNU__,1 #define IFDEF .ifdef #define ELSE .else @@ -45,6 +49,15 @@ IF 0 #define END .end #define EXTERN .extern +.macro FUNC_DECL name +.global \name +.func \name +\name: +.endm +.macro FUNC_END name +.endfunc +.endm + ;# ~GNU ENDIF @@ -68,14 +81,18 @@ SECTION_CODE FUNC_DECL CallProc2 ;# rcx=SystemProc* edx=ParamCount - mov [rsp+8h], r12 - mov [rsp+10h], r13 - mov [rsp+18h], r14 - ;#mov [rsp+20h], r15 + mov [rsp+8], r12 + mov [rsp+16], r13 + mov [rsp+24], r14 + ;#mov [rsp+32], r15 ;# The stack is unaligned on function entry. We have to calculate the required ;# stack size for our parameters + maybe 8 padding bytes to end up 16 byte aligned. +IFDEF __GNU__ +#define pSystemProc r14 +ELSE pSystemProc equ r14 +ENDIF mov pSystemProc, rcx ;# Save SystemProc* ;# Not required since we zero-extend eax: xor rax, rax mov r13d, edx ;# Save ParamCount @@ -84,9 +101,9 @@ FUNC_DECL CallProc2 ;# rcx=SystemProc* edx=ParamCount jnz noparamalignpadding lea eax, [eax+8] ;# sizeof(params) + 8 will make us 16 byte aligned noparamalignpadding: - cmp eax, 28h ;# The ABI guarantees shadow space for the 4 register parameters + cmp eax, 40 ;# The ABI guarantees shadow space for the 4 register parameters ja computedstacksize - mov eax, 28h ;# Minimum (4*8) + 8 to align + mov eax, 40 ;# Minimum (4*8) + 8 to align computedstacksize: mov r12d, eax ;# Save stack size (Zero-extended mov) sub rsp, r12 @@ -170,10 +187,10 @@ capturegle_done: ;# add/lea rsp and pop is valid in the epilog. Unwind might fail on our version? add rsp, r12 ;# Restore stack ;# Restore nonvolatile registers: - mov r12, [rsp+8h] - mov r13, [rsp+10h] - mov r14, [rsp+18h] - ;#mov r15, [rsp+20h] + mov r12, [rsp+8] + mov r13, [rsp+16] + mov r14, [rsp+24] + ;#mov r15, [rsp+32] ret FUNC_END CallProc2 diff --git a/Contrib/System/Source/Call-amd64CPP.S b/Contrib/System/Source/Call-amd64CPP.S new file mode 100644 index 00000000..33d3beec --- /dev/null +++ b/Contrib/System/Source/Call-amd64CPP.S @@ -0,0 +1,8 @@ +#ifdef _MSC_VER +#error "MSVC is supposed to use the plain .S file!" +#endif +#if 0 +ERROR: assembler-with-cpp required! +#else +#include "Call-amd64.S" +#endif diff --git a/Contrib/System/Source/Call-amd64CPP.sx b/Contrib/System/Source/Call-amd64CPP.sx new file mode 100644 index 00000000..76734d0c --- /dev/null +++ b/Contrib/System/Source/Call-amd64CPP.sx @@ -0,0 +1,8 @@ +#ifdef _MSC_VER +#error "MSVC is supposed to use the plain .S file!" +#endif +#if 0 +ERROR: assembler-with-cpp required! +#else +#include "Call-amd64CPP.S" +#endif diff --git a/Contrib/System/Source/System.c b/Contrib/System/Source/System.c index 452240da..42f94533 100644 --- a/Contrib/System/Source/System.c +++ b/Contrib/System/Source/System.c @@ -276,31 +276,8 @@ PLUGINFUNCTION(Get) #ifdef _WIN64 /* -TODO: CallProc/Back not implemeted. -Fake the behavior of the System plugin for the LoadImage API function so MUI works. -BUGBUG: MUI is leaking DeleteObject and failing GetClientRect +BUGBUG: TODO: CallBack support not implemeted! */ -#ifndef SYSTEM_PARTIALCALLSUPPORT -SystemProc* CallProc(SystemProc *proc) -{ - INT_PTR ret, *place; - LastError = lstrcmp(proc->ProcName, sizeof(TCHAR) > 1 ? _T("LoadImageW") : _T("LoadImageA")); - if (!LastError) - { - ret = (INT_PTR) LoadImage((HINSTANCE)proc->Params[1].Value, - (LPCTSTR)proc->Params[2].Value, (UINT)proc->Params[3].Value, - (int)proc->Params[4].Value, (int)proc->Params[5].Value, - (UINT)proc->Params[6].Value); - LastError = GetLastError(); - } - else - proc->ProcResult = PR_ERROR, ret = 0; - place = (INT_PTR*) proc->Params[0].Value; - if (proc->Params[0].Option != -1) place = (INT_PTR*) &(proc->Params[0].Value); - if (place) *place = ret; - return proc; -} -#endif // ~SYSTEM_PARTIALCALLSUPPORT SystemProc* CallBack(SystemProc *proc) { proc->ProcResult = PR_ERROR; @@ -461,7 +438,7 @@ SystemProc *PrepareProc(BOOL NeedForCall) TCHAR *ibuf, *ib, *sbuf, *cbuf, *cb; unsigned int UsedTString = 0; -#if defined(__GNUC__) && ((__GNUC__ * 1000) + __GNUC_MINOR__) < 4006 +#ifdef __GNUC__ temp3 = 0; // "warning: 'temp3' may be used uninitialized in this function": temp3 is set to 0 when we start parsing a new parameter #endif @@ -692,14 +669,7 @@ SystemProc *PrepareProc(BOOL NeedForCall) case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'): case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'): // Numeric inline -#if defined(__GNUC__) && ((__GNUC__ * 1000) + __GNUC_MINOR__) >= 4006 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuninitialized" // temp3 is set to 0 when we start parsing a new parameter -#endif if (temp3 == 0) -#if defined(__GNUC__) && ((__GNUC__ * 1000) + __GNUC_MINOR__) >= 4006 -#pragma GCC diagnostic pop -#endif { ib--; // It's stupid, I know, but I'm too lazy to do another thing @@ -768,14 +738,7 @@ SystemProc *PrepareProc(BOOL NeedForCall) if (temp3 == 1) proc->Params[ParamIndex].Output = (int) temp4; // Note: As long as we never assign a pointer to temp4 when parsing a destination the cast to int is OK. // Next parameter is output or something else -#if defined(__GNUC__) && ((__GNUC__ * 1000) + __GNUC_MINOR__) >= 4006 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wuninitialized" -#endif temp3++; -#if defined(__GNUC__) && ((__GNUC__ * 1000) + __GNUC_MINOR__) >= 4006 -#pragma GCC diagnostic pop -#endif } ChangesDone = PCD_DONE; @@ -1384,7 +1347,7 @@ Returns offset for element Clone of SystemProc structure */ unsigned int GetCloneOffset(void) { - return (unsigned int)(&(((SystemProc *)0)->Clone)); + return (unsigned int)(UINT_PTR) (&(((SystemProc *)0)->Clone)); } /* @@ -1392,7 +1355,7 @@ Returns offset for element ProcName of SystemProc structure */ unsigned int GetProcNameOffset(void) { - return (unsigned int)(&(((SystemProc *)0)->ProcName)); + return (unsigned int)(UINT_PTR) (&(((SystemProc *)0)->ProcName)); } /* @@ -1400,7 +1363,7 @@ Returns offset for element ArgsSize of SystemProc structure */ unsigned int GetArgsSizeOffset(void) { - return (unsigned int)(&(((SystemProc *)0)->ArgsSize)); + return (unsigned int)(UINT_PTR) (&(((SystemProc *)0)->ArgsSize)); } /* @@ -1432,7 +1395,7 @@ Returns offset for element Size of ProcParameter structure */ unsigned int GetSizeOffsetParam(void) { - return (unsigned int)(&(((ProcParameter *)0)->Size)); + return (unsigned int)(UINT_PTR) (&(((ProcParameter *)0)->Size)); } /* diff --git a/Contrib/System/Source/System.h b/Contrib/System/Source/System.h index df53f376..d7a6d9e7 100644 --- a/Contrib/System/Source/System.h +++ b/Contrib/System/Source/System.h @@ -155,10 +155,8 @@ extern void ParamsDeAllocate(SystemProc *proc); extern void ParamsIn(SystemProc *proc); extern void ParamsOut(SystemProc *proc); #ifdef SYSTEM_AMD64 -#ifdef SYSTEM_PARTIALCALLSUPPORT extern SystemProc* CallProc2(SystemProc *proc, UINT_PTR ParamCount); #define CallProc(p) CallProc2((p), (p)->ParamCount) // ParamCount is passed as a parameter so CallProc2 can determine the required stack size without a function call -#endif #else // !SYSTEM_AMD64 extern SystemProc* CallProc(SystemProc *proc); #endif // ~SYSTEM_AMD64 diff --git a/Contrib/UserInfo/UserInfo.c b/Contrib/UserInfo/UserInfo.c index 609344f4..11274164 100644 --- a/Contrib/UserInfo/UserInfo.c +++ b/Contrib/UserInfo/UserInfo.c @@ -71,7 +71,7 @@ TCHAR* GetAccountTypeHelper(BOOL CheckTokenForGroupDeny) (CHECKTOKENMEMBERSHIP) GetProcAddress( GetModuleHandle(_T("ADVAPI32")), "CheckTokenMembership"); #else - _CheckTokenMembership = CheckTokenMembership; + CheckTokenMembership; #endif // Use "old school" membership check? diff --git a/Contrib/nsDialogs/browse.c b/Contrib/nsDialogs/browse.c index f5ef584f..0af4dd4f 100644 --- a/Contrib/nsDialogs/browse.c +++ b/Contrib/nsDialogs/browse.c @@ -8,9 +8,7 @@ #include "defs.h" -#ifdef _countof -#define COUNTOF _countof -#else +#ifndef COUNTOF #define COUNTOF(a) (sizeof(a)/sizeof(a[0])) #endif diff --git a/Contrib/nsDialogs/nsDialogs.c b/Contrib/nsDialogs/nsDialogs.c index 7ed84d57..2243b038 100644 --- a/Contrib/nsDialogs/nsDialogs.c +++ b/Contrib/nsDialogs/nsDialogs.c @@ -33,7 +33,7 @@ static COLORREF GetLinkColor() struct nsControl* NSDFUNC GetControl(HWND hwCtl) { - unsigned id = (unsigned) GetProp(hwCtl, NSCONTROL_ID_PROP); + unsigned id = (unsigned)(UINT_PTR) GetProp(hwCtl, NSCONTROL_ID_PROP); if (id == 0 || id > g_dialog.controlCount) { diff --git a/Contrib/zip2exe/main.cpp b/Contrib/zip2exe/main.cpp index 70d37b94..2c6f3bf6 100644 --- a/Contrib/zip2exe/main.cpp +++ b/Contrib/zip2exe/main.cpp @@ -7,9 +7,7 @@ #include #include -#ifdef _countof -#define COUNTOF _countof -#else +#ifndef COUNTOF #define COUNTOF(a) (sizeof(a)/sizeof(a[0])) #endif diff --git a/SCons/Config/gnu b/SCons/Config/gnu index 74595e45..f6014493 100644 --- a/SCons/Config/gnu +++ b/SCons/Config/gnu @@ -4,7 +4,17 @@ Import('defenv') ### imports -Import('FlagsConfigure') +Import('FlagsConfigure GetOptionOrEnv') + +### HACKS! +if GetOptionOrEnv('NSIS_SCONS_GNU_ENVPATHHACK'): + import os + defenv['ENV']['PATH'] = os.getenv('PATH') # Major hack! + import_env = ['SystemDrive', 'SystemRoot', 'TEMP', 'TMP', 'PATHEXT'] + for var in import_env: + if var in os.environ: + defenv['ENV'][var] = os.environ.get(var, '') + #print defenv.Dump() ### cross compiling @@ -15,10 +25,11 @@ def cross_env(env): ### flags def entry(x,u): - if x == 'NSISWinMainNOCRT': - x = '_' + x - elif x == 'DllMain': - x = '_DllMain@12' + if defenv['TARGET_ARCH'] == 'x86': + if x == 'NSISWinMainNOCRT': + x = '_' + x + elif x == 'DllMain': + x = '_DllMain@12' return '-Wl,-e%s' % x defenv['ENTRY_FLAG'] = entry @@ -203,6 +214,12 @@ conf.Finish() # sure the sections will be written in the correct order. # +if defenv['TARGET_ARCH'] == 'amd64': + stub_env.Append(LINKFLAGS = ['-B pei-x86-64']) + stub_uenv.Append(LINKFLAGS = ['-B pei-x86-64']) +else: + stub_env.Append(LINKFLAGS = ['--oformat pei-i386']) + stub_uenv.Append(LINKFLAGS = ['--oformat pei-i386']) stub_env.Append(LINKFLAGS = ['-T', File('linker_script').rfile()]) stub_uenv.Append(LINKFLAGS = ['-T', File('linker_script').rfile()]) diff --git a/SCons/Config/linker_script b/SCons/Config/linker_script index 193e0474..5a8bf450 100644 --- a/SCons/Config/linker_script +++ b/SCons/Config/linker_script @@ -1,4 +1,6 @@ -OUTPUT_FORMAT(pei-i386) +/* +OUTPUT_FORMAT(pei-i386 VS pei-x86-64) must be set somewhere else +*/ SECTIONS { .text __image_base__ + __section_alignment__ : diff --git a/SCons/utils.py b/SCons/utils.py index 0bf3e540..9528c53b 100644 --- a/SCons/utils.py +++ b/SCons/utils.py @@ -118,4 +118,17 @@ def FlagsConfigure(env): """ return env.Configure(custom_tests = { 'CheckCompileFlag' : check_compile_flag, 'CheckLinkFlag': check_link_flag }) -Export('AddAvailableLibs AddZLib FlagsConfigure GetAvailableLibs') +def GetOptionOrEnv(name, defval = None): + """ + Get option set on scons command line or in os.environ + """ + import os + #if optenv and optenv.has_key(name): + # return optenv[name] + if ARGUMENTS.has_key(name): + return ARGUMENTS[name] + if os.environ.has_key(name): + return os.environ[name] + return defval + +Export('AddAvailableLibs AddZLib FlagsConfigure GetAvailableLibs GetOptionOrEnv') diff --git a/SConstruct b/SConstruct index e97a858c..06cf5b2b 100644 --- a/SConstruct +++ b/SConstruct @@ -336,7 +336,7 @@ defenv['DISTSUFFIX'] = '' if defenv['TARGET_ARCH'] == 'amd64': defenv['DISTSUFFIX'] += '-amd64' if defenv.has_key('CODESIGNER'): - defenv['DISTSUFFIX'] = '-signed' + defenv['DISTSUFFIX'] += '-signed' defenv.Execute(Delete('$ZIPDISTDIR')) defenv.Execute(Delete('$INSTDISTDIR')) @@ -448,7 +448,7 @@ def DistributeExtras(env, target, examples, docs): ###################################################################### if defenv['MSTOOLKIT']: - if ARGUMENTS.get('MSVC_USE_SCRIPT', ''): + if GetOptionOrEnv('MSVC_USE_SCRIPT', '!') != '!': defenv['MSVC_USE_SCRIPT'] = ARGUMENTS.get('MSVC_USE_SCRIPT') defenv.Tool('mstoolkit', toolpath = [Dir('SCons/Tools').rdir()]) diff --git a/Source/Platform.h b/Source/Platform.h index a6d1df23..09396b51 100644 --- a/Source/Platform.h +++ b/Source/Platform.h @@ -139,9 +139,7 @@ typedef DWORDLONG ULONGLONG,*PULONGLONG; #endif #endif -#ifdef _countof -#define COUNTOF _countof -#else +#ifndef COUNTOF #define COUNTOF(a) (sizeof(a)/sizeof(a[0])) #endif @@ -1020,22 +1018,22 @@ typedef struct tagVS_FIXEDFILEINFO { /* _tprintf on Windows/MSVCRT treats %s as TCHAR* and on POSIX %s is always char*! -Always use our NPRI* (NsisPRInt[Narrow|Wide]*) defines in format strings when calling +Always use our NPRI* (NsisPRInt*[Narrow|Wide]) defines in format strings when calling functions from tchar.h (Similar to the way works) Example: _tprintf(_T("Hello %") NPRIs _T("\n"), _T("World")); */ #ifdef _WIN32 # define NPRIs _T("s") -# define NPRINs _T("hs") -# define NPRIWs _T("ls") // ws also works, not sure which is most compatible +# define NPRIns _T("hs") +# define NPRIws _T("ls") // ws also works, not sure which is most compatible # ifndef _WIN64 # define NPRIp _T(".8x") -# define NPRINp ".8x" +# define NPRIpN ".8x" # endif #else // !_WIN32 -# define NPRINs _T("s") -# define NPRIWs _T("ls") +# define NPRIns _T("s") +# define NPRIws _T("ls") # ifdef _UNICODE # define NPRIs _T("ls") # else // !_UNICODE @@ -1044,7 +1042,7 @@ Example: _tprintf(_T("Hello %") NPRIs _T("\n"), _T("World")); #endif // ~_WIN32 #ifndef NPRIp # define NPRIp _T("p") -# define NPRINp "p" +# define NPRIpN "p" #endif #endif // EOF diff --git a/Source/ResourceEditor.cpp b/Source/ResourceEditor.cpp index 905c6dee..7c660af2 100644 --- a/Source/ResourceEditor.cpp +++ b/Source/ResourceEditor.cpp @@ -849,7 +849,7 @@ void CResourceDirectory::RemoveEntry(int i) { } unsigned int CResourceDirectory::CountEntries() { - return BUGBUG64TRUNCATE(unsigned int,m_vEntries.size()); + return truncate_cast(unsigned int,m_vEntries.size()); } // Returns the index of a directory entry with the specified name diff --git a/Source/build.cpp b/Source/build.cpp index e9415473..b4402389 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -448,7 +448,7 @@ void CEXEBuild::init_shellconstantvalues() // see Source\exehead\util.c for implementation details // basically, it knows it needs to get folders from the registry when the 0x80 is on const char* msg = "Internal compiler error: too many strings added to strings block before adding shell constants!"; - ERROR_MSG(_T("%") NPRINs, msg); + ERROR_MSG(_T("%") NPRIns, msg); throw out_of_range(msg); } @@ -469,7 +469,7 @@ void CEXEBuild::init_shellconstantvalues() || uncf64_def != cf64_def) { const char* msg = "Internal compiler error: installer's shell constants are different than uninstallers!"; - ERROR_MSG(_T("%") NPRINs, msg); + ERROR_MSG(_T("%") NPRIns, msg); throw out_of_range(msg); } } @@ -602,7 +602,7 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP { // starts with a $ but not $$. bool bProceced=false; - if ( *p ) + if (*p) { const TCHAR *pUserVarName = p; while (isSimpleChar(*pUserVarName)) @@ -610,10 +610,10 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP while (pUserVarName > p) { - if (m_ShellConstants.get(p, BUGBUG64TRUNCATE(int, pUserVarName-p)) >= 0) + if (m_ShellConstants.get(p, truncate_cast(int, (size_t)(pUserVarName - p))) >= 0) break; // Woops it's a shell constant - int idxUserVar = m_UserVarNames.get(p, BUGBUG64TRUNCATE(int, pUserVarName-p)); + int idxUserVar = m_UserVarNames.get(p, truncate_cast(int, (size_t)(pUserVarName - p))); if (idxUserVar >= 0) { // Well, using variables inside string formating doens't mean @@ -641,7 +641,7 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP while (pShellConstName > p) { // Look for the identifier in the shell constants list of strings. - int idxConst = m_ShellConstants.get((TCHAR*)p, BUGBUG64TRUNCATE(int, pShellConstName - p)); + int idxConst = m_ShellConstants.get((TCHAR*)p, truncate_cast(int, (size_t)(pShellConstName - p))); // If found... if (idxConst >= 0) @@ -857,6 +857,14 @@ int CEXEBuild::add_db_data(IMMap *mmap) // returns offset bufferlen = INT_MAX-st-sizeof(int); // so maximize compressor room and hope the file compresses well db->resize(st + bufferlen + sizeof(int)); +#if defined(NSIS_CONFIG_COMPRESSION_SUPPORT) && defined(__GNUC__) && defined(_WIN64) // There is another one of these, remove both when fixed + // BUGBUG: zlib is currently broken on 64-bit MinGW + if (compressor == &zlib_compressor) + { + ERROR_MSG(_T("\nError: ZLib is currently broken on this platform!\n")); + return -1; + } +#endif int n = compressor->Init(build_compress_level, build_compress_dict_size); if (n != C_OK) { @@ -1123,8 +1131,7 @@ int CEXEBuild::add_function(const TCHAR *funname) // ns_func contains all the function names defined. int addr=ns_func.add(funname,0); - int x; - int n=cur_functions->getlen()/sizeof(section); + int n=cur_functions->getlen()/sizeof(section), x; section *tmp=(section*)cur_functions->get(); for (x = 0; x < n; x ++) { @@ -2566,6 +2573,15 @@ int CEXEBuild::write_output(void) RET_UNLESS_OK( check_write_output_errors() ); +#if defined(NSIS_CONFIG_COMPRESSION_SUPPORT) && defined(__GNUC__) && defined(_WIN64) // There is another one of these, remove both when fixed + // BUGBUG: zlib is currently broken on 64-bit MinGW + if (compressor == &zlib_compressor) + { + ERROR_MSG(_T("\nError: ZLib is currently broken on this platform!\n")); + return PS_ERROR; + } +#endif + has_called_write_output=true; #ifdef NSIS_CONFIG_PLUGIN_SUPPORT @@ -3198,7 +3214,7 @@ int CEXEBuild::uninstall_generate() compressor->Compress(0); if (compressor->GetNextOut() - obuf > 0) { - udata.add(obuf, BUGBUG64TRUNCATE(int, compressor->GetNextOut() - obuf)); + udata.add(obuf, truncate_cast(int, (size_t)(compressor->GetNextOut() - obuf))); } } @@ -3215,7 +3231,7 @@ int CEXEBuild::uninstall_generate() compressor->SetNextOut(obuf, sizeof(obuf)); compressor->Compress(0); if (compressor->GetNextOut() - obuf > 0) - udata.add(obuf, BUGBUG64TRUNCATE(int, compressor->GetNextOut() - obuf)); + udata.add(obuf, truncate_cast(int, (size_t)(compressor->GetNextOut() - obuf))); } ubuild_datablock.release(); @@ -3229,7 +3245,7 @@ int CEXEBuild::uninstall_generate() compressor->SetNextOut(obuf, sizeof(obuf)); compressor->Compress(C_FINISH); if (compressor->GetNextOut() - obuf > 0) - udata.add(obuf, BUGBUG64TRUNCATE(int, compressor->GetNextOut() - obuf)); + udata.add(obuf, truncate_cast(int, (size_t)(compressor->GetNextOut() - obuf))); else break; } compressor->End(); diff --git a/Source/crc32.c b/Source/crc32.c index 9bf0a620..6abb952c 100644 --- a/Source/crc32.c +++ b/Source/crc32.c @@ -19,10 +19,11 @@ #include "Platform.h" #include "crc32.h" #include "exehead/config.h" + #ifdef NSIS_CONFIG_CRC_SUPPORT // this is based on the (slow,small) CRC32 implementation from zlib. -crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, unsigned int len) +crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, size_t len) { static crc32_t crc_table[256]; diff --git a/Source/crc32.h b/Source/crc32.h index 706e20ff..9bb506f2 100644 --- a/Source/crc32.h +++ b/Source/crc32.h @@ -16,16 +16,17 @@ * Reviewed for Unicode support by Jim Park -- 08/24/2007 */ -#include "Platform.h" - #ifndef ___CRC32__H___ #define ___CRC32__H___ +#include "Platform.h" +#include // size_t + typedef UINT32 crc32_t; #ifdef __cplusplus extern "C" #endif -crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, unsigned int len); +crc32_t NSISCALL CRC32(crc32_t crc, const unsigned char *buf, size_t len); #endif//!___CRC32__H___ diff --git a/Source/exehead/Ui.c b/Source/exehead/Ui.c index 26375764..618c2558 100644 --- a/Source/exehead/Ui.c +++ b/Source/exehead/Ui.c @@ -290,7 +290,7 @@ FORCE_INLINE int NSISCALL ui_doinstall(void) if (header->install_reg_key_ptr) { myRegGetStr( - (HKEY)header->install_reg_rootkey, + (HKEY)(UINT_PTR)header->install_reg_rootkey, GetNSISStringNP(header->install_reg_key_ptr), GetNSISStringNP(header->install_reg_value_ptr), ps_tmpbuf, diff --git a/Source/exehead/bgbg.c b/Source/exehead/bgbg.c index d03e8c3f..c7eac28a 100644 --- a/Source/exehead/bgbg.c +++ b/Source/exehead/bgbg.c @@ -77,7 +77,7 @@ LRESULT CALLBACK BG_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (header->bg_textcolor != -1) { - HFONT newFont = CreateFontIndirect((LOGFONT *) header->blocks[NB_BGFONT].offset); + HFONT newFont = CreateFontIndirect((LOGFONT*) header->blocks[NB_BGFONT].offset); if (newFont) { HFONT oldFont; diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index e91a63d0..ed3b4850 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -189,10 +189,10 @@ static LONG NSISCALL myRegDeleteKeyEx(HKEY thiskey, LPCTSTR lpSubKey, int onlyif static HKEY NSISCALL GetRegRootKey(int hRootKey) { if (hRootKey) - return (HKEY) hRootKey; + return (HKEY) (UINT_PTR) hRootKey; // HKEY_LOCAL_MACHINE - HKEY_CURRENT_USER == 1 - return (HKEY) ((int) HKEY_CURRENT_USER + g_exec_flags.all_user_var); + return (HKEY) ((UINT_PTR) HKEY_CURRENT_USER + g_exec_flags.all_user_var); } static HKEY NSISCALL myRegOpenKey(REGSAM samDesired) @@ -870,7 +870,7 @@ static int NSISCALL ExecuteEntry(entry *entry_) TCHAR *buf2=GetStringFromParm(0x22); GetStringFromParm(0x15); // For update_status_text_buf1 update_status_text_buf1(LANG_EXECSHELL); - x=(int)ShellExecute(g_hwnd,buf0[0]?buf0:NULL,buf3,buf2[0]?buf2:NULL,state_output_directory,parm3); + x=(int)(INT_PTR)ShellExecute(g_hwnd,buf0[0]?buf0:NULL,buf3,buf2[0]?buf2:NULL,state_output_directory,parm3); if (x < 33) { log_printf5(_T("ExecShell: warning: error (\"%s\": file:\"%s\" params:\"%s\")=%d"),buf0,buf3,buf2,x); diff --git a/Source/exehead/fileform.c b/Source/exehead/fileform.c index 9fcb4e9d..2d6e172d 100644 --- a/Source/exehead/fileform.c +++ b/Source/exehead/fileform.c @@ -17,6 +17,10 @@ */ #include "../Platform.h" +#if defined(__cplusplus) && defined(truncate_cast) +#undef BUGBUG64TRUNCATE +#define BUGBUG64TRUNCATE truncate_cast +#endif #include "fileform.h" #include "util.h" #include "state.h" @@ -327,7 +331,13 @@ const TCHAR * NSISCALL loadHeaders(int cl_flags) // set offsets to real memory offsets rather than installer's header offset left = BLOCKS_NUM; while (left--) - header->blocks[left].offset += (int)data; + { +#ifdef DEBUG + if (h.length_of_header < header->blocks[left].offset) + return _LANG_GENERIC_ERROR; // Should never happen +#endif + header->blocks[left].offset += BUGBUG64TRUNCATE(UINT, (UINT_PTR) data); + } #ifdef NSIS_COMPRESS_WHOLE header->blocks[NB_DATA].offset = dbd_pos; @@ -398,7 +408,7 @@ int NSISCALL _dodecomp(int offset, HANDLE hFileOut, unsigned char *outbuf, int o if (err<0) return -4; - u=BUGBUG64TRUNCATE(int, (char*)g_inflate_stream.next_out - outbuffer); + u=BUGBUG64TRUNCATE(int, (size_t)((char*)g_inflate_stream.next_out - outbuffer)); tc=GetTickCount(); if (g_exec_flags.status_update & 1 && (tc - ltc > 200 || !input_len)) @@ -501,7 +511,7 @@ static int NSISCALL __ensuredata(int amount) { return -3; } - r=(DWORD)g_inflate_stream.next_out-(DWORD)_outbuffer; + r=BUGBUG64TRUNCATE(DWORD,(UINT_PTR)g_inflate_stream.next_out)-BUGBUG64TRUNCATE(DWORD,(UINT_PTR)_outbuffer); if (r) { if (!WriteFile(dbd_hFile,_outbuffer,r,&t,NULL) || r != t) diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h index e8bd9962..9f47d52e 100644 --- a/Source/exehead/fileform.h +++ b/Source/exehead/fileform.h @@ -258,7 +258,7 @@ typedef struct // nsis blocks struct block_header { - int offset; + /*UINT_PTR*/ int offset; // BUGBUG: This should probably be UINT_PTR but that currently crashes :( int num; }; @@ -554,10 +554,10 @@ extern int g_flags; extern int g_filehdrsize; extern int g_is_uninstaller; -#define g_pages ((page*)g_blocks[NB_PAGES].offset) -#define g_sections ((section*)g_blocks[NB_SECTIONS].offset) -#define num_sections (g_blocks[NB_SECTIONS].num) -#define g_entries ((entry*)g_blocks[NB_ENTRIES].offset) +#define g_pages ( (page*) g_blocks[NB_PAGES].offset ) +#define g_sections ( (section*) g_blocks[NB_SECTIONS].offset ) +#define num_sections ( g_blocks[NB_SECTIONS].num ) +#define g_entries ( (entry*) g_blocks[NB_ENTRIES].offset ) #endif #endif //_FILEFORM_H_ diff --git a/Source/exehead/util.c b/Source/exehead/util.c index b9bf86e7..437a4ebf 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -567,7 +567,9 @@ void RenameViaWininit(const TCHAR* prevName, const TCHAR* newName) */ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) { - BOOL fOk = 0; +#ifndef _WIN64 // Shut up GCC unused warning + BOOL fOk = FALSE; +#endif typedef BOOL (WINAPI *mfea_t)(LPCTSTR lpExistingFileName,LPCTSTR lpNewFileName,DWORD dwFlags); mfea_t mfea; #ifdef _WIN64 @@ -577,7 +579,10 @@ void NSISCALL MoveFileOnReboot(LPCTSTR pszExisting, LPCTSTR pszNew) if (mfea) #endif { - fOk=mfea(pszExisting, pszNew, MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING); +#ifndef _WIN64 // Shut up GCC unused warning + fOk= +#endif + mfea(pszExisting, pszNew, MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING); } #ifndef _WIN64 if (!fOk) diff --git a/Source/growbuf.cpp b/Source/growbuf.cpp index 76400d82..b2edb50c 100644 --- a/Source/growbuf.cpp +++ b/Source/growbuf.cpp @@ -30,36 +30,37 @@ using namespace std; // Default constructor -GrowBuf::GrowBuf() { m_alloc=m_used=m_zero=0; m_s=NULL; m_bs=32768; } +GrowBuf::GrowBuf() { m_alloc=m_used=0, m_zero=false, m_s=NULL, m_bs=32768; } // Destructor GrowBuf::~GrowBuf() { free(m_s); } -void GrowBuf::set_zeroing(int zero) { m_zero=zero; } +void GrowBuf::set_zeroing(bool zero) { m_zero=zero; } -int GrowBuf::add(const void *data, int len) +GrowBuf::size_type GrowBuf::add(const void *data, GrowBuf::size_type len) { - if (len<=0) return 0; + if (len<=0) return 0; // BUGBUG: Why is this returning 0? It should return m_used? resize(m_used+len); memcpy((BYTE*)m_s+m_used-len,data,len); return m_used-len; } -void GrowBuf::resize(int newlen) +void GrowBuf::resize(GrowBuf::size_type newlen) { - int os=m_alloc; // old size - int ou=m_used; // old used + const size_type orgalloc=m_alloc; + const size_type orgused=m_used; + m_used=newlen; if (newlen > m_alloc) { - void *n; + void *newstor; // Jim Park: Not sure why we don't just add m_bs. Multiplying by 2 // makes m_bs meaningless after a few resizes. So TinyGrowBuf // isn't very tiny. m_alloc = newlen*2 + m_bs; - n = realloc(m_s, m_alloc); - if (!n) + newstor = realloc(m_s, m_alloc); + if (!newstor) { extern int g_display_errors; if (g_display_errors) @@ -67,8 +68,8 @@ void GrowBuf::resize(int newlen) PrintColorFmtMsg_ERR(_T("\nack! realloc(%d) failed, trying malloc(%d)!\n"),m_alloc,newlen); } m_alloc=newlen; // try to malloc the minimum needed - n=malloc(m_alloc); - if (!n) + newstor=malloc(m_alloc); + if (!newstor) { extern void quit(); if (g_display_errors) @@ -77,15 +78,15 @@ void GrowBuf::resize(int newlen) } quit(); } - memcpy(n,m_s,min(newlen,os)); + memcpy(newstor,m_s,min(newlen,orgalloc)); free(m_s); } - m_s=n; + m_s=newstor; } // Zero out the new buffer area - if (m_zero && m_used > ou) - memset((BYTE*)m_s + ou, 0, m_used - ou); + if (m_zero && m_used > orgused) + memset((BYTE*)m_s + orgused, 0, m_used - orgused); if (!m_used && m_alloc > 2*m_bs) // only free if you resize to 0 and we're > 64k or // 2K in the case of TinyGrowBuf @@ -96,7 +97,7 @@ void GrowBuf::resize(int newlen) } } -int GrowBuf::getlen() const { return m_used; } +GrowBuf::size_type GrowBuf::getlen() const { return m_used; } void *GrowBuf::get() const { return m_s; } void GrowBuf::swap(GrowBuf&other) diff --git a/Source/growbuf.h b/Source/growbuf.h index bc0d2297..2106dfe1 100644 --- a/Source/growbuf.h +++ b/Source/growbuf.h @@ -26,6 +26,7 @@ class IGrowBuf { public: + typedef int size_type; // Hopefully we can change this at some point virtual ~IGrowBuf() {} /** @@ -34,19 +35,19 @@ class IGrowBuf * @param len Size of the data in bytes. * @return the previous logical size in bytes before the addition. */ - virtual int add(const void *data, int len)=0; + virtual size_type add(const void *data, size_type len)=0; /** * Resizes the buffer to hold the number of bytes specified. * @param newlen the desired logical size of the buffer. */ - virtual void resize(int newlen)=0; + virtual void resize(size_type newlen)=0; /** * Get the length of the logical buffer in bytes. * @return the length in bytes */ - virtual int getlen() const=0; + virtual size_type getlen() const=0; /** * Get the buffer itself. @@ -72,7 +73,7 @@ class GrowBuf : public IGrowBuf * Set whether to zero out buffer * @param zero A boolean value. */ - void set_zeroing(int zero); + void set_zeroing(bool zero); /** * Add data to the buffer. @@ -80,22 +81,21 @@ class GrowBuf : public IGrowBuf * @param len Size of the data in bytes. * @return the previous logical size in bytes before the addition. */ - int add(const void *data, int len); + size_type add(const void *data, size_type len); /** * Resizes the buffer to hold the number of bytes specified. + * Setting the newlen to 0 will cause the buffer to be at most + * 2*m_bs bytes long. (It will free the buffer if > 2*m_bs.) * @param newlen the desired logical size of the buffer. */ - void resize(int newlen); + void resize(size_type newlen); /** * Get the length of the logical buffer in bytes. - * Setting the newlen to 0 will cause the buffer to be at most - * 2*m_bs bytes long. (It will free the buffer if > 2*m_bs.) - * * @return the length in bytes */ - int getlen() const; + size_type getlen() const; /** * Get the buffer itself. @@ -107,12 +107,12 @@ class GrowBuf : public IGrowBuf private: void *m_s; /* the storage buffer */ - int m_alloc; /* allocated bytes */ - int m_used; /* how many bytes of the buffer is used? */ - int m_zero; /* should storage be zeroed out? */ + size_type m_alloc; /* allocated bytes */ + size_type m_used; /* how many bytes of the buffer is used? */ + bool m_zero; /* should storage be zeroed out? */ protected: - int m_bs; // byte-size to grow by + unsigned short m_bs; // byte-size to grow by }; /** diff --git a/Source/icon.cpp b/Source/icon.cpp index 834d2269..40cdc409 100644 --- a/Source/icon.cpp +++ b/Source/icon.cpp @@ -228,7 +228,7 @@ static IconPairs get_icon_order(IconGroup icon1, IconGroup icon2) FIX_ENDIAN_INT32(sorted_icons1[i].meta.dwRawSize), FIX_ENDIAN_INT32(sorted_icons2[i].meta.dwRawSize) ); - pair.size_index = BUGBUG64TRUNCATE(unsigned int,i); + pair.size_index = truncate_cast(unsigned int,i); result.push_back(pair); } @@ -242,7 +242,7 @@ static IconPairs get_icon_order(IconGroup icon1, IconGroup icon2) pair.index1 = sorted_icons1[i].index; pair.index2 = 0xffff; pair.size = FIX_ENDIAN_INT32(sorted_icons1[i].meta.dwRawSize); - pair.size_index = BUGBUG64TRUNCATE(unsigned int,i); + pair.size_index = truncate_cast(unsigned int,i); } if (i < sorted_icons2.size()) @@ -250,7 +250,7 @@ static IconPairs get_icon_order(IconGroup icon1, IconGroup icon2) pair.index2 = sorted_icons2[i].index; pair.index1 = 0xffff; pair.size = FIX_ENDIAN_INT32(sorted_icons2[i].meta.dwRawSize); - pair.size_index = BUGBUG64TRUNCATE(unsigned int,i); + pair.size_index = truncate_cast(unsigned int,i); } result.push_back(pair); diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp index 4f8367b6..33c23f7b 100644 --- a/Source/makenssi.cpp +++ b/Source/makenssi.cpp @@ -118,8 +118,11 @@ static void init_signals(HWND notify_hwnd) #ifdef _WIN32 DWORD id; HANDLE hThread = CreateThread(NULL, 0, sigint_event_msg_handler, (LPVOID)notify_hwnd, 0, &id); - SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); - if (hThread) CloseHandle(hThread); + if (hThread) + { + SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); + CloseHandle(hThread); + } #endif } @@ -326,7 +329,7 @@ static inline int makensismain(int argc, TCHAR **argv) { initialparsefail=!HasReqParam(argv,++argpos,argc,true); if (initialparsefail) break; - hostnotifyhandle=(HWND)_ttol(argv[argpos]); + hostnotifyhandle=(HWND)(INT_PTR) _ttol(argv[argpos]); // MSDN says we should sign extend HWNDs: msdn.microsoft.com/en-us/library/aa384203 #ifdef _WIN32 if (!IsWindow(hostnotifyhandle)) hostnotifyhandle=0; #endif @@ -394,7 +397,7 @@ static inline int makensismain(int argc, TCHAR **argv) // The host can override the output format if they want to LPARAM lp=MAKELONG(outputenc.GetCodepage(),outputbom); LRESULT mr=SendMessage(hostnotifyhandle,MakensisAPI::QUERYHOST,MakensisAPI::QH_OUTPUTCHARSET,lp); - if (mr) outputenc.SetCodepage((WORD)--mr), outputbom = -1; + if (mr) outputenc.SetCodepage((WORD)(--mr)), outputbom = -1; } if (!WinStdIO_OStreamInit(g_osdata_stdout,g_output,outputenc.GetCodepage(),outputbom)) diff --git a/Source/script.cpp b/Source/script.cpp index 618288ff..1ead1627 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -52,6 +52,8 @@ using namespace std; #define MAX_INCLUDEDEPTH 10 +#define REGROOTKEYTOINT(hk) ( (INT) (((INT_PTR)(hk)) & 0xffffffff) ) // Masking off non-existing top bits to make GCC happy + static UINT read_line_helper(NStreamLineReader&lr, TCHAR*buf, UINT cch) { // Helper function for reading lines from text files. buf MUST be valid and cch MUST be > 1! @@ -662,7 +664,7 @@ void CEXEBuild::ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hi if (t-in > 1) // handle multibyte chars (no escape) { - linedata.add((void*)in,BUGBUG64TRUNCATE(int,(t-in)*sizeof(TCHAR))); + linedata.add((void*)in,truncate_cast(int, (size_t)((t-in)*sizeof(TCHAR)))); in=t; continue; } @@ -1213,7 +1215,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *mbufb=(TCHAR*)m_macros.get(); const size_t mcb=((mend)-mbeg)*sizeof(TCHAR), mbufcb=m_macros.getlen(); memmove(mbeg,mend,mbufcb-(((mbeg-mbufb)*sizeof(TCHAR))+mcb)); - m_macros.resize(BUGBUG64TRUNCATE(int,mbufcb-mcb)); + m_macros.resize(truncate_cast(int,(size_t)(mbufcb-mcb))); SCRIPT_MSG(_T("!macroundef: %") NPRIs _T("\n"),mname); } return PS_OK; @@ -2293,7 +2295,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int k=line.gettoken_enum(1,rootkeys[0]); if (k == -1) k=line.gettoken_enum(1,rootkeys[1]); if (k == -1) PRINTHELP() - build_header.install_reg_rootkey=(INT)rootkey_tab[k]; + build_header.install_reg_rootkey=REGROOTKEYTOINT(rootkey_tab[k]); if (!build_header.install_reg_rootkey) PRINTHELP() // SHCTX is invalid here build_header.install_reg_key_ptr = add_string(line.gettoken_str(2),0); if (line.gettoken_str(2)[0] == _T('\\')) @@ -5339,7 +5341,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int k=line.gettoken_enum(2,rootkeys[0]); if (k == -1) k=line.gettoken_enum(2,rootkeys[1]); if (ent.offsets[0] == -1 || k == -1) PRINTHELP() - ent.offsets[1]=(INT)rootkey_tab[k]; + ent.offsets[1]=REGROOTKEYTOINT(rootkey_tab[k]); ent.offsets[2]=add_string(line.gettoken_str(3)); ent.offsets[3]=add_string(line.gettoken_str(4)); if (which_token == TOK_READREGDWORD) ent.offsets[4]=1; @@ -5371,7 +5373,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (k == -1) k=line.gettoken_enum(a,rootkeys[1]); if (k == -1) PRINTHELP() ent.which=EW_DELREG; - ent.offsets[1]=(INT)rootkey_tab[k]; + ent.offsets[1]=REGROOTKEYTOINT(rootkey_tab[k]); ent.offsets[2]=add_string(line.gettoken_str(a+1)); ent.offsets[3]=(which_token==TOK_DELETEREGKEY)?0:add_string(line.gettoken_str(a+2)); if (line.gettoken_str(a+1)[0] == _T('\\')) @@ -5391,7 +5393,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (k == -1) k=line.gettoken_enum(1,rootkeys[1]); if (k == -1) PRINTHELP() ent.which=EW_WRITEREG; - ent.offsets[0]=(INT)rootkey_tab[k]; + ent.offsets[0]=REGROOTKEYTOINT(rootkey_tab[k]); ent.offsets[1]=add_string(line.gettoken_str(2)); if (line.gettoken_str(2)[0] == _T('\\')) warning_fl(_T("%") NPRIs _T(": registry path name begins with \'\\\', may cause problems"),line.gettoken_str(0)); @@ -5458,7 +5460,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int k=line.gettoken_enum(2,rootkeys[0]); if (k == -1) k=line.gettoken_enum(2,rootkeys[1]); if (ent.offsets[0] == -1 || k == -1) PRINTHELP() - ent.offsets[1]=(INT)rootkey_tab[k]; + ent.offsets[1]=REGROOTKEYTOINT(rootkey_tab[k]); ent.offsets[2]=add_string(line.gettoken_str(3)); ent.offsets[3]=add_string(line.gettoken_str(4)); ent.offsets[4]=which_token == TOK_ENUMREGKEY; diff --git a/Source/strlist.cpp b/Source/strlist.cpp index e0469731..48456ba5 100644 --- a/Source/strlist.cpp +++ b/Source/strlist.cpp @@ -124,7 +124,7 @@ unsigned int ExeHeadStringList::find(const void *ptr, unsigned int cchF, WORD co #ifndef NDEBUG if (!cbMB) { - const TCHAR *fmt = _T("Unable to convert%")NPRINs _T(" string \"%")NPRIs _T("\" to codepage %u\n"); + const TCHAR *fmt = _T("Unable to convert%")NPRIns _T(" string \"%")NPRIs _T("\" to codepage %u\n"); PrintColorFmtMsg_ERR(fmt,(processed ? " processed" : ""),find,codepage); } #endif @@ -160,7 +160,8 @@ unsigned int ExeHeadStringList::find(const void *ptr, unsigned int cchF, WORD co else delete[] bufMB; } - return BUGBUG64TRUNCATE(unsigned int, retval); + // -1 is a valid magic return value but we must avoid the truncation check in truncate_cast + return retval != (size_t)(-1) ? truncate_cast(unsigned int,retval) : (unsigned int) retval; } int ExeHeadStringList::add(const TCHAR *str, WORD codepage, bool processed) @@ -203,7 +204,7 @@ int StringList::add(const TCHAR *str, int case_sensitive) { int a=find(str,case_sensitive); if (a >= 0 && case_sensitive!=-1) return a; - return m_gr.add(str,BUGBUG64TRUNCATE(int, (_tcslen(str)+1)*sizeof(TCHAR)))/sizeof(TCHAR); + return m_gr.add(str,truncate_cast(int,(_tcslen(str)+1)*sizeof(TCHAR)))/sizeof(TCHAR); } // use 2 for case sensitive end-of-string matches too @@ -233,9 +234,9 @@ int StringList::find(const TCHAR *str, int case_sensitive, int *idx/*=NULL*/) co str_slen < offs_slen && // check for end of string !_tcscmp(s + offs + offs_slen - str_slen,str)) { - return BUGBUG64TRUNCATE(int, offs + offs_slen - str_slen); + return truncate_cast(int,offs + offs_slen - str_slen); } - offs += BUGBUG64TRUNCATE(int, offs_slen + 1); + offs += truncate_cast(int,offs_slen + 1); if (idx) (*idx)++; } @@ -316,7 +317,7 @@ int DefineList::addn(const TCHAR *name, size_t maxvallen, const TCHAR *value) extern void quit(); if (g_display_errors) { - PrintColorFmtMsg_ERR(_T("\nInternal compiler error #12345: DefineList malloc(%lu) failed.\n"), BUGBUG64TRUNCATE(unsigned long,cbVal)); + PrintColorFmtMsg_ERR(_T("\nInternal compiler error #12345: DefineList malloc(%lu) failed.\n"), truncate_cast(unsigned long,cbVal)); } quit(); } diff --git a/Source/util.cpp b/Source/util.cpp index 461b27a3..8e54da36 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -456,8 +456,8 @@ void create_code_page_string(TCHAR *buf, size_t len, UINT code_page) if (!g_nrt_iconv_narrowloc) NSISRT_Initialize(); // For winchar.cpp unit test switch(code_page) { - case CP_ACP: _sntprintf(buf, len, _T("%") NPRINs, iconv_ACP); return; - case CP_OEMCP: _sntprintf(buf, len, _T("%") NPRINs, iconv_OEM); return; + case CP_ACP: _sntprintf(buf, len, _T("%") NPRIns, iconv_ACP); return; + case CP_OEMCP: _sntprintf(buf, len, _T("%") NPRIns, iconv_OEM); return; case CP_UTF8: _sntprintf(buf, len, _T("UTF-8")); return; case 1200: // UTF16LE case 1201: // UTF16BE diff --git a/Source/util.h b/Source/util.h index 71d1f06d..32fe9c12 100644 --- a/Source/util.h +++ b/Source/util.h @@ -140,7 +140,7 @@ int WinStdIO_wprintf(const wchar_t*Fmt, ...); #define _vftprintf WinStdIO_vfwprintf #endif // ~MAKENSIS #else -int RunChildProcessRedirected(LPCWSTR cmd); +int RunChildProcessRedirected(LPCSTR cmd); #endif // ~_UNICODE #define ResetPrintColor() FlushOutputAndResetPrintColor() // For reset ONLY, use PrintColorFmtMsg(0,NULL ... #define SetPrintColorWARN() PrintColorFmtMsg(1|0x10, NULL, (va_list)NULL) @@ -274,10 +274,28 @@ FILE* my_fopen(const TCHAR *path, const char *mode); // round a value up to be a multiple of 512 // assumption: T is an int type -template -inline T align_to_512(const T x) { - return (x+511) & ~511; +template inline T align_to_512(const T x) { return (x+511) & ~511; } + +// some values need to be truncated from size_t to [unsigned] int, using this function is better than a plain cast +template inline R internaltruncate_cast(T t) { + assert((~((T)0)) > T(0)); // Only unsigned types supported right now + if (sizeof(T) > sizeof(R)) assert(t <= (T)(~((R)0))); // BUGBUG: What if R is a signed type? + return (R) t; } +template inline R debugtruncate_cast(T t,const char*f,unsigned int l) { +#ifdef MAKENSIS + if (sizeof(T) > sizeof(R) && !( (t <= (T)(~((R)0))) )) { + _tprintf(_T("unsafe truncate_cast: %") NPRIns _T(":%u\n"),f,l); + if (sizeof(T) <= sizeof(void*)) _tprintf(_T("\t0x%p > %0xp\n"),(void*)(UINT_PTR)(t),(void*)(UINT_PTR)(~((R)0))); + } +#endif + return internaltruncate_cast(t); +} +#if defined(DEBUG) || defined(_WIN64) // Always enabled for experimental 64-bit builds +#define truncate_cast(ret_t,input) debugtruncate_cast((input),__FILE__,__LINE__) +#else +#define truncate_cast(ret_t,input) internaltruncate_cast((input)) +#endif // ================ // ResourceManagers diff --git a/Source/writer.cpp b/Source/writer.cpp index cf5c66e7..d7e29fdf 100644 --- a/Source/writer.cpp +++ b/Source/writer.cpp @@ -96,9 +96,28 @@ void writer_sink::write_growbuf(const IGrowBuf *b) write_data(b->get(), b->getlen()); } +namespace hlp { + template static inline bool issigned() { return T(-1) < T(0); } + template static inline bool issigned(const T&t) { return issigned(); } +} + void growbuf_writer_sink::write_data(const void *data, const size_t size) { - m_buf->add(data, BUGBUG64TRUNCATE(int, size)); + // TODO: Replace all of this with a simple call when GrowBuf is changed to use size_t + if (sizeof(size) == sizeof(sink_type::size_type) && hlp::issigned(size) == hlp::issigned()) + { + m_buf->add(data, truncate_cast(sink_type::size_type, size)); + } + else + { + size_t left = size; + sink_type::size_type cbmaxadd = INT_MAX, cb; + for (char *p = (char *) data; left; p += cb, left -= cb) + { + cb = left >= (size_t) cbmaxadd ? cbmaxadd : (sink_type::size_type) left; + m_buf->add(p, cb); + } + } } void file_writer_sink::write_data(const void *data, const size_t size) @@ -114,6 +133,6 @@ void file_writer_sink::write_data(const void *data, const size_t size) void crc_writer_sink::write_data(const void *data, const size_t size) { - *m_crc = CRC32(*m_crc, (const unsigned char *) data, BUGBUG64TRUNCATE(unsigned int, size)); + *m_crc = CRC32(*m_crc, (const unsigned char *) data, size); } #endif diff --git a/Source/writer.h b/Source/writer.h index a2bfd999..bbc7b486 100644 --- a/Source/writer.h +++ b/Source/writer.h @@ -55,12 +55,13 @@ protected: class growbuf_writer_sink : public writer_sink { public: - growbuf_writer_sink(IGrowBuf *buf, bool build_unicode) : m_buf(buf) { m_build_unicode=build_unicode; } + typedef IGrowBuf sink_type; + growbuf_writer_sink(sink_type *buf, bool build_unicode) : m_buf(buf) { m_build_unicode=build_unicode; } virtual void write_data(const void *data, const size_t size); private: - IGrowBuf *m_buf; + sink_type *m_buf; };