From b278e8975dd3940e980a247ecb56b81464bb242d Mon Sep 17 00:00:00 2001 From: anders_k Date: Fri, 1 Jun 2018 17:28:41 +0000 Subject: [PATCH] Fixed !macroundef of last defined macro bug git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6998 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/history.but | 2 ++ Source/Tests/preprocessor.nsi | 34 ++++++++++++++++++++++++++++++++++ Source/scriptpp.cpp | 20 ++++++++++---------- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/Docs/src/history.but b/Docs/src/history.but index 952e5e0d..9b5d8046 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -14,6 +14,8 @@ Released on ??? ??th, 20?? \b MakeNSIS prints -CMDHELP to stdout (\W{http://sf.net/p/nsis/bugs/1203}{bug #1203}) +\b Fixed !macroundef of last defined macro bug + \S2{} Translations \b Fixed minor Spanish bug (\W{http://sf.net/p/nsis/bugs/1205}{bug #1205}) diff --git a/Source/Tests/preprocessor.nsi b/Source/Tests/preprocessor.nsi index c04a64a3..28989049 100644 --- a/Source/Tests/preprocessor.nsi +++ b/Source/Tests/preprocessor.nsi @@ -107,6 +107,39 @@ this shouldn't be compiled !macroend +; test macros +!macro TM_0 +!macroend +!macro TM_1 +!error "Wrong TM_1" +!macroend +!macro TM_2 +!error "Wrong TM_2" +!macroend +!macroundef TM_2 ; Undefine the last macro +!macro TM_2 +!if 0 +!endif +!macroend +!ifmacrodef TM_1 +!macroundef TM_1 ; Undefine "in the middle" macro +!endif +!macro TM_1 +!macroend +!insertmacro TM_1 +!insertmacro TM_2 + +!macro TM_Recursion def +!if '${${def}}' < 42 + !define /redef /math ${def} '${${def}}' + 1 + !insertmacro ${__MACRO__} ${def} +!endif +!macroend +!define /redef OUT1 0 +!insertmacro TM_Recursion OUT1 +${ASSERT} '${OUT1} = 42' + + ; testing of two math functions and a macro hack :) !define increase "!insertmacro increase" !macro increase DEFINE @@ -194,6 +227,7 @@ SectionEnd !macroend +!insertmacro TEST_SCOPE "macro" __MACRO__ y !insertmacro TEST_SCOPES "global" y n n n n Section test diff --git a/Source/scriptpp.cpp b/Source/scriptpp.cpp index 759a12f2..b20e6fd8 100644 --- a/Source/scriptpp.cpp +++ b/Source/scriptpp.cpp @@ -235,15 +235,17 @@ void CEXEBuild::del_date_time_predefines() TCHAR* CEXEBuild::GetMacro(const TCHAR *macroname, TCHAR**macroend /*= 0*/) { TCHAR *t = (TCHAR*)m_macros.get(), *mbeg, *mbufbeg = t; + size_t cbAll = m_macros.getlen(), cchAll = cbAll / sizeof(TCHAR); for (; t && *t; ++t) { mbeg = t; + if (t-mbufbeg >= cchAll) break; const bool foundit = !_tcsicmp(mbeg, macroname); t += _tcslen(t) + 1; // advance over macro name // advance over parameters while (*t) t += _tcslen(t) + 1; - t++; + t++; // Separator between parameters and data // advance over data while (*t) t += _tcslen(t) + 1; @@ -253,15 +255,13 @@ TCHAR* CEXEBuild::GetMacro(const TCHAR *macroname, TCHAR**macroend /*= 0*/) if (macroend) *macroend = ++t; return mbeg; } - - if (t-mbufbeg >= m_macros.getlen()-1) break; } return 0; } int CEXEBuild::pp_macro(LineParser&line) { - const TCHAR*const macroname = line.gettoken_str(1); + const TCHAR*const macroname = line.gettoken_str(1), *tokstr; if (!macroname[0]) PRINTHELP() if (MacroExists(macroname)) { @@ -272,22 +272,22 @@ int CEXEBuild::pp_macro(LineParser&line) for (int pc=2; pc < line.getnumtokens(); pc++) { - if (!line.gettoken_str(pc)[0]) + if (!(tokstr = line.gettoken_str(pc))[0]) { ERROR_MSG(_T("!macro: macro parameter %d is empty, not valid!\n"), pc-1); return PS_ERROR; } for (int a = 2; a < pc; a++) { - if (!_tcsicmp(line.gettoken_str(pc), line.gettoken_str(a))) + if (!_tcsicmp(tokstr, line.gettoken_str(a))) { - ERROR_MSG(_T("!macro: macro parameter named %") NPRIs _T(" is used multiple times!\n"), line.gettoken_str(pc)); + ERROR_MSG(_T("!macro: macro parameter named %") NPRIs _T(" is used multiple times!\n"), tokstr); return PS_ERROR; } } - m_macros.add(line.gettoken_str(pc), (int)(_tcslen(line.gettoken_str(pc))+1)*sizeof(TCHAR)); + m_macros.add(tokstr, (int)(_tcslen(tokstr)+1)*sizeof(TCHAR)); } - m_macros.add(_T(""), sizeof(_T(""))); + m_macros.add(_T(""), sizeof(_T(""))); // Separator between parameters and data for (;;) { @@ -333,7 +333,7 @@ int CEXEBuild::pp_macro(LineParser&line) else m_macros.add(_T(" "), sizeof(_T(" "))); linecnt++; } - m_macros.add(_T(""), sizeof(_T(""))); + m_macros.add(_T(""), sizeof(_T(""))); // End of data return PS_OK; }