From 74ffaada4ecf3bf423aca6b1104b7f0f2cbacf66 Mon Sep 17 00:00:00 2001 From: wizou Date: Fri, 28 May 2010 14:09:08 +0000 Subject: [PATCH] Merging various fixes from latest Jim Park repository git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6096 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/StartMenu/StartMenu.c | 12 ++++++++---- Contrib/System/Source/System.c | 21 ++++++++++++++++++++- Contrib/nsExec/nsexec.c | 6 ++++-- Source/script.cpp | 10 +++++----- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/Contrib/StartMenu/StartMenu.c b/Contrib/StartMenu/StartMenu.c index b72a9e7b..39db5817 100644 --- a/Contrib/StartMenu/StartMenu.c +++ b/Contrib/StartMenu/StartMenu.c @@ -368,10 +368,14 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_COMMAND: if (LOWORD(wParam) == IDC_DIRLIST && HIWORD(wParam) == LBN_SELCHANGE) { - SendMessage(hwDirList, LB_GETTEXT, SendMessage(hwDirList, LB_GETCURSEL, 0, 0), (WPARAM)buf); - if (autoadd) - lstrcat(lstrcat(buf, _T("\\")), progname); - SetWindowText(hwLocation, buf); + LRESULT selection = SendMessage(hwDirList, LB_GETCURSEL, 0, 0); + if (selection != LB_ERR) + { + SendMessage(hwDirList, LB_GETTEXT, selection, (WPARAM)buf); + if (autoadd) + lstrcat(lstrcat(buf, _T("\\")), progname); + SetWindowText(hwLocation, buf); + } } else if (LOWORD(wParam) == IDC_CHECK && HIWORD(wParam) == BN_CLICKED) { diff --git a/Contrib/System/Source/System.c b/Contrib/System/Source/System.c index a2a6f963..b18c5eea 100644 --- a/Contrib/System/Source/System.c +++ b/Contrib/System/Source/System.c @@ -801,7 +801,26 @@ SystemProc *PrepareProc(BOOL NeedForCall) } // Get proc address - if ((proc->Proc = NSISGetProcAddress(proc->Dll, proc->ProcName)) == NULL) + proc->Proc = NSISGetProcAddress(proc->Dll, proc->ProcName); +#ifdef _UNICODE + if ((proc->Proc != NULL) && + (proc->ProcName[0] == _T('l') && + proc->ProcName[1] == _T('s') && + proc->ProcName[2] == _T('t') && + proc->ProcName[3] == _T('r')) && + (lstrcmpi(_T("kernel32"), proc->DllName) == 0 || lstrcmpi(_T("kernel32.dll"), proc->DllName) == 0)) + { + int lastCharIdx = lstrlen(proc->ProcName) - 1; + + if (lastCharIdx > 1 && + proc->ProcName[lastCharIdx] != _T('A') && + proc->ProcName[lastCharIdx] != _T('W')) + { + proc->Proc = NULL; // force using W variant + } + } +#endif + if (proc->Proc == NULL) { #ifdef _UNICODE // automatic W discover diff --git a/Contrib/nsExec/nsexec.c b/Contrib/nsExec/nsexec.c index b19e2b38..b67a7513 100644 --- a/Contrib/nsExec/nsexec.c +++ b/Contrib/nsExec/nsexec.c @@ -225,7 +225,8 @@ params: if (!pExec[0]) { pushstring(_T("error")); - *(pExec-2) = _T('\0'); // skip space and quote + if (pExec-2 >= g_exec) + *(pExec-2) = _T('\0'); // skip space and quote if (executor) DeleteFile(executor); GlobalFree(g_exec); return; @@ -393,7 +394,8 @@ done: CloseHandle(read_stdout); CloseHandle(newstdin); CloseHandle(read_stdin); - *(pExec-2) = _T('\0'); // skip space and quote + if (pExec-2 >= g_exec) + *(pExec-2) = _T('\0'); // skip space and quote if (executor) DeleteFile(executor); GlobalFree(g_exec); if (log) { diff --git a/Source/script.cpp b/Source/script.cpp index 81039fe0..5b9d271d 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -3144,7 +3144,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) *++p=0; bool endSlash = (str[0] && str[_tcslen(str)-1] == _T('\\')); - if (tmpstr.getlen() || endSlash) tmpstr.add(str,_tcslen(str)); + if (tmpstr.getlen() || endSlash) tmpstr.add(str,sizeof(TCHAR)*_tcslen(str)); // if we have valid contents and not ending on slash, then done if (!endSlash && (str[0] || tmpstr.getlen())) break; @@ -3155,7 +3155,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR *thisline=str; if (tmpstr.getlen()) { - tmpstr.add(_T("\0"),1); + tmpstr.add(_T("\0"),sizeof(TCHAR)); thisline=(TCHAR *)tmpstr.get(); } @@ -3233,15 +3233,15 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) while (*src) { if (ignoreCase ? _tcsnicmp(src,search,searchlen) : _tcsncmp(src,search,searchlen)) - valout.add(src++,1); + valout.add(src++,sizeof(TCHAR)); else { - valout.add(replace,replacelen); + valout.add(replace,sizeof(TCHAR)*replacelen); src+=searchlen; } } - valout.add(_T(""),1); + valout.add(_T(""),sizeof(TCHAR)); definedlist.del(define); // allow changing variables since we'll often use this in series