From 0e851e4b79433b9eae0dec9832565171474b1b27 Mon Sep 17 00:00:00 2001 From: anders_k Date: Sun, 17 Mar 2013 21:13:07 +0000 Subject: [PATCH] Reduced !include/!insertmacro recursion stack usage (Bug #3067954) git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6306 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/history.but | 2 ++ Source/build.h | 5 +++++ Source/script.cpp | 16 +++++++--------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Docs/src/history.but b/Docs/src/history.but index af1dcceb..12b65b70 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -12,6 +12,8 @@ Released on ?, 2013 \b MakeNSIS /NOTIFYHWND uses a (optional) new event name to abort compilation, see build.cpp/h for details. +\b Reduced !include/!insertmacro recursion stack usage (\W{http://sourceforge.net/support/tracker.php?aid=3067954}{bug #3067954}) + \S2{} Translations \b Changed LANGFILE macro in LangFile.nsh diff --git a/Source/build.h b/Source/build.h index 1bb4bdbe..9180345e 100644 --- a/Source/build.h +++ b/Source/build.h @@ -98,6 +98,10 @@ class CEXEBuild { void initialize(const TCHAR *makensis_path); ~CEXEBuild(); + enum { + MAX_LINELENGTH = 16384 // NSI/NSH line limit, in TCHARs (including \0) + }; + void warning(const TCHAR *s, ...); // to add a warning to the compiler's warning list. void warning_fl(const TCHAR *s, ...); // warning with file name and line count void ERROR_MSG(const TCHAR *s, ...) const; @@ -192,6 +196,7 @@ class CEXEBuild { #endif int doParse(const TCHAR *str); int doCommand(int which_token, LineParser &line); + TCHAR m_templinebuf[MAX_LINELENGTH]; // Buffer used by parseScript() & doCommand(), not recursion safe! int do_add_file(const TCHAR *lgss, int attrib, int recurse, int *total_files, const TCHAR *name_override=0, int generatecode=1, int *data_handle=0, diff --git a/Source/script.cpp b/Source/script.cpp index 2fd0e97b..38fc729a 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -51,7 +51,6 @@ using namespace std; #endif #define MAX_INCLUDEDEPTH 10 -#define MAX_LINELENGTH 16384 #ifdef NSIS_SUPPORT_STANDARD_PREDEFINES // Added by Sunil Kamath 11 June 2003 @@ -770,7 +769,7 @@ void CEXEBuild::ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hi int CEXEBuild::parseScript() { assert(curlinereader); - TCHAR str[MAX_LINELENGTH]; + TCHAR *str = m_templinebuf; NStreamLineReader &linereader = *curlinereader; for (;;) @@ -1115,8 +1114,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) for (;;) { - TCHAR str[MAX_LINELENGTH]; - TCHAR *p=str; + TCHAR *str = m_templinebuf, *p = str; UINT lrres = curlinereader->ReadLine(str,MAX_LINELENGTH); if (NStream::OK != lrres) { @@ -1139,7 +1137,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) while (*p) p++; if (p > str) p--; while (p >= str && (*p == _T('\r') || *p == _T('\n') || *p == _T(' ') || *p == _T('\t'))) p--; - *++p=0; + *++p = 0; LineParser l2(false); if (!l2.parse(str)) { @@ -1411,7 +1409,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) ERROR_MSG(_T("%s: error reading version info from \"%s\"\n"), cmdname, line.gettoken_str(1)); return PS_ERROR; } - TCHAR symbuf[MAX_LINELENGTH], numbuf[30], *basesymname = line.gettoken_str(2); + TCHAR *symbuf = m_templinebuf, numbuf[30], *basesymname = line.gettoken_str(2); DWORD vals[] = { high>>16, high&0xffff, low>>16, low&0xffff }; SCRIPT_MSG(_T("%s: %s (%u.%u.%u.%u)->(%s<1..4>)\n"), cmdname, line.gettoken_str(1), vals[0], vals[1], vals[2], vals[3], basesymname); @@ -3043,7 +3041,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } if (fp) { - TCHAR str[MAX_LINELENGTH]; + TCHAR *str=m_templinebuf; for (;;) { TCHAR *p=str; *p=0; @@ -3359,14 +3357,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) int req_parm = (line.getnumtokens() - parmOffs)/2; GrowBuf tmpstr; - TCHAR str[MAX_LINELENGTH]; + TCHAR *str=m_templinebuf; for (;;) { tmpstr.resize(0); for (;;) { str[0]=0; - _fgetts(str,COUNTOF(str),fp); + _fgetts(str,MAX_LINELENGTH,fp); if (!str[0]) break; // eof TCHAR *p=str;