From 5c627b632c66502ac88fb747bd1a87ceb01b1991 Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 6 Sep 2002 20:19:52 +0000 Subject: [PATCH] Buffer bugs fixed, should work better. Hopefully it won't crash anymore. git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@945 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Makensisw/makensisw.cpp | 6 ++- Contrib/Makensisw/makensisw.h | 4 +- Contrib/Makensisw/noclib.cpp | 15 ------ Contrib/Makensisw/noclib.h | 1 - Contrib/Makensisw/utils.cpp | 93 ++++++++++++++++++++------------- 5 files changed, 64 insertions(+), 55 deletions(-) diff --git a/Contrib/Makensisw/makensisw.cpp b/Contrib/Makensisw/makensisw.cpp index 76e13a50..fd1820c2 100644 --- a/Contrib/Makensisw/makensisw.cpp +++ b/Contrib/Makensisw/makensisw.cpp @@ -75,6 +75,8 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { case WM_INITDIALOG: { g_hwnd=hwndDlg; + g_output_exe = (char *)GlobalAlloc(GPTR, 1); + g_input_script = (char *)GlobalAlloc(GPTR, 1); HICON hIcon = LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_ICON)); SetClassLong(hwndDlg,GCL_HICON,(long)hIcon); HFONT hFont = CreateFont(14,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,"Courier New"); @@ -133,6 +135,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { CloseHandle(g_hThread); g_hThread=0; } + EnableItems(g_hwnd); if (g_retcode==0) { MessageBeep(MB_ICONASTERISK); if (g_warnings) SetTitle(g_hwnd,"Finished with Warnings"); @@ -142,7 +145,6 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { MessageBeep(MB_ICONEXCLAMATION); SetTitle(g_hwnd,"Compile Error: See Log for Details"); } - EnableItems(g_hwnd); return TRUE; } case WM_COMMAND: @@ -220,7 +222,7 @@ BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { l.hwndOwner = hwndDlg; l.lpstrFilter = "Log Files (*.log)\0Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; l.lpstrFile = buf; - l.nMaxFile = 1023; + l.nMaxFile = MAX_STRING-1; l.lpstrTitle = "Save Output"; l.lpstrDefExt = "log"; l.lpstrInitialDir = NULL; diff --git a/Contrib/Makensisw/makensisw.h b/Contrib/Makensisw/makensisw.h index 49722839..8458e5eb 100644 --- a/Contrib/Makensisw/makensisw.h +++ b/Contrib/Makensisw/makensisw.h @@ -51,8 +51,8 @@ extern const char *NSISW_VERSION; extern char *g_script; extern HWND g_hwnd; extern HANDLE g_hThread; -extern char g_output_exe[1024]; -extern char g_input_script[1024]; +extern char *g_output_exe; +extern char *g_input_script; // makensisw int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow); diff --git a/Contrib/Makensisw/noclib.cpp b/Contrib/Makensisw/noclib.cpp index bced115a..0d4fbe51 100644 --- a/Contrib/Makensisw/noclib.cpp +++ b/Contrib/Makensisw/noclib.cpp @@ -35,19 +35,4 @@ char *my_strrchr(const char *string, int c) { void *my_memset(void *dest, int c, size_t count) { for (size_t i = 0; i < count; i++) ((char*)dest)[i]=c; return dest; -} - -char *my_strstr(const char *string, const char *strCharSet) { - if (!*strCharSet) return (char*)string; - if (lstrlen(string) < lstrlen(strCharSet)) return 0; - size_t chklen=lstrlen(string)-lstrlen(strCharSet); - char *s1, *s2; - for (size_t i = 0; i < chklen; i++) { - s1=&((char*)string)[i]; - s2=(char*)strCharSet; - while (*s1++ == *s2++) - if (!*s2) - return &((char*)string)[i]; - } - return 0; } \ No newline at end of file diff --git a/Contrib/Makensisw/noclib.h b/Contrib/Makensisw/noclib.h index 7928393f..51841522 100644 --- a/Contrib/Makensisw/noclib.h +++ b/Contrib/Makensisw/noclib.h @@ -27,6 +27,5 @@ Contribution by kickik char *my_strrchr(const char *string, int c); void *my_memset(void *dest, int c, size_t count); -char *my_strstr(const char *string, const char *strCharSet); #endif \ No newline at end of file diff --git a/Contrib/Makensisw/utils.cpp b/Contrib/Makensisw/utils.cpp index 414f0826..f34b1503 100644 --- a/Contrib/Makensisw/utils.cpp +++ b/Contrib/Makensisw/utils.cpp @@ -51,8 +51,8 @@ void ClearLog(HWND hwnd) { SetDlgItemText(hwnd, IDC_LOGWIN, ""); } -char g_output_exe[1024]; -char g_input_script[1024]; +char *g_output_exe; +char *g_input_script; extern BOOL g_warnings; void LogMessage(HWND hwnd,const char *str) { @@ -83,37 +83,58 @@ void DisableItems(HWND hwnd) { } void EnableItems(HWND hwnd) { - int len=SendDlgItemMessage(hwnd,IDC_LOGWIN,WM_GETTEXTLENGTH,0,0); - if (len>0) { - HGLOBAL memory; - char *existing_text; - memory = GlobalAlloc(GMEM_MOVEABLE,len+1); - existing_text = (char *)GlobalLock(memory); - if (!existing_text) return; - existing_text[0]=0; - GetDlgItemText(hwnd, IDC_LOGWIN, existing_text, len); - char *p=existing_text; - char *p2; - char *p3; - if ((p2=my_strstr(p,"\r\nOutput: \""))) { - while (*p2 != '\"') p2++; - p2++; - if ((p3=my_strstr(p2,"\"\r\n")) && p3 < my_strstr(p2,"\r\n")) { - *p3=0; - lstrcpy(g_output_exe,p2); - } - } - p=my_strstr(existing_text,"\r\nProcessing script file: \""); - if (p) { - while (*p++ != '"'); - char *p2=my_strstr(p,"\r\n"); - lstrcpyn(g_input_script,p,p2-p); - } - if (my_strstr(existing_text, " warning:") || my_strstr(existing_text, " warnings:")) { - g_warnings = TRUE; - } - GlobalUnlock(memory); - } + #define MSG(a) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,0,0) + #define MSG1(a,b) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,b,0) + #define MSG2(a,b,c) SendDlgItemMessage(hwnd,IDC_LOGWIN,a,b,c) + + static char *outputExeBuf, *inputScriptBuf; + + if (inputScriptBuf) { + GlobalFree(inputScriptBuf); + g_input_script = inputScriptBuf = 0; + } + if (outputExeBuf) { + GlobalFree(outputExeBuf); + g_output_exe = outputExeBuf = 0; + } + + if (g_input_script) GlobalFree(g_input_script); + if (g_output_exe) GlobalFree(g_output_exe); + + FINDTEXT ft; + ft.chrg.cpMin = 0; + ft.chrg.cpMax = MSG(WM_GETTEXTLENGTH); + ft.lpstrText = "Processing script file: \""; + long charPos = MSG2(EM_FINDTEXT, 0, (LPARAM)&ft); + long lineNum = MSG2(EM_EXLINEFROMCHAR, 0, charPos); + long lineLength = MSG1(EM_LINELENGTH, charPos); + inputScriptBuf = (char *)GlobalAlloc(GPTR, lineLength+1); + *(WORD *)inputScriptBuf = (WORD)lineLength+1; + MSG2(EM_GETLINE, lineNum, (WPARAM)inputScriptBuf); + g_input_script = inputScriptBuf+lstrlen("Processing script file: \""); + char *p = g_input_script; + while (*p && *p != '"') p++; + *p = 0; + + ft.lpstrText = "Output: \""; + charPos = MSG2(EM_FINDTEXT, 0, (LPARAM)&ft); + lineNum = MSG2(EM_EXLINEFROMCHAR, 0, charPos); + lineLength = MSG1(EM_LINELENGTH, charPos); + outputExeBuf = (char *)GlobalAlloc(GPTR, lineLength+1); + *(WORD *)outputExeBuf = (WORD)lineLength+1; + MSG2(EM_GETLINE, lineNum, (WPARAM)outputExeBuf); + g_output_exe = outputExeBuf+lstrlen("Output: \""); + p = g_output_exe; + while (*p && *p != '"') p++; + *p = 0; + + g_warnings = FALSE; + + ft.lpstrText = "warning:"; + if (MSG2(EM_FINDTEXT, 0, (LPARAM)&ft) != -1) g_warnings++; + ft.lpstrText = "warnings:"; + if (MSG2(EM_FINDTEXT, 0, (LPARAM)&ft) != -1) g_warnings++; + HMENU m = GetMenu(hwnd); if (g_output_exe[0]) { EnableWindow(GetDlgItem(hwnd,IDC_TEST),1); @@ -130,7 +151,7 @@ void EnableItems(HWND hwnd) { static BOOL g_appended = FALSE; void CompileNSISScript() { - char s[MAX_PATH]; + static char *s; ClearLog(g_hwnd); SetTitle(g_hwnd,NULL); SetBranding(g_hwnd); @@ -144,8 +165,10 @@ void CompileNSISScript() { return; } if (!g_appended) { + if (s) GlobalFree(s); + s = (char *)GlobalAlloc(GPTR, lstrlen(g_script)+lstrlen(EXENAME)+1); wsprintf(s,"%s %s",EXENAME,g_script); - lstrcpy(g_script,s); + g_script = s; g_appended = TRUE; } // Disable buttons during compile