Preprocessor code in dead blocks need to be ignored even if it is invalid

Test case:
!macro dummy p1
!macroend
!if 0 ; The next line does not properly quote its string but it is not !else nor !endif so it has to be ignored
!insertmacro dummy "bar'
!endif



git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6632 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2015-11-05 04:46:14 +00:00
parent 2a341bc918
commit ce249976f7
4 changed files with 26 additions and 13 deletions

View file

@ -176,7 +176,7 @@ class CEXEBuild {
void update_exehead(const unsigned char *new_exehead, size_t new_size);
// tokens.cpp
bool is_ppbranch_token(TCHAR *s);
bool is_ppbranch_token(const TCHAR *s);
bool is_pp_token(int tkid);
bool is_unsafe_pp_token(int tkid);
int get_commandtoken(const TCHAR *s, int *np, int *op, int *pos);

View file

@ -150,7 +150,7 @@ double LineParser::gettoken_number(int token, int *success/*=0*/) const
TCHAR* LineParser::gettoken_str(int token) const
{
token+=m_eat;
if (token < 0 || token >= m_nt) return (TCHAR*)_T("");
if (token < 0 || token >= m_nt) return (TCHAR*) _T("");
return m_tokens[token];
}
@ -201,7 +201,8 @@ int LineParser::doline(TCHAR *line, int ignore_escaping/*=0*/)
else line++;
}
}
else {
else
{
int lstate=0; // 1=", 2=`, 4='
if (*line == _T(';') || *line == _T('#'))
{
@ -213,7 +214,8 @@ int LineParser::doline(TCHAR *line, int ignore_escaping/*=0*/)
m_incommentblock = true;
line+=2;
}
else {
else
{
if (*line == _T('\"')) lstate=1;
else if (*line == _T('\'')) lstate=2;
else if (*line == _T('`')) lstate=4;
@ -222,8 +224,10 @@ int LineParser::doline(TCHAR *line, int ignore_escaping/*=0*/)
TCHAR *p = line;
while (*line)
{
if (line[0] == _T('$') && line[1] == _T('\\')) {
switch (line[2]) {
if (line[0] == _T('$') && line[1] == _T('\\'))
{
switch (line[2])
{
case _T('"'):
case _T('\''):
case _T('`'):
@ -247,8 +251,10 @@ int LineParser::doline(TCHAR *line, int ignore_escaping/*=0*/)
int i;
m_tokens[m_nt]=(TCHAR*)malloc((nc+1)*sizeof(TCHAR));
for (i = 0; p < line; i++, p++) {
if (!ignore_escaping && p[0] == _T('$') && p[1] == _T('\\')) {
switch (p[2]) {
if (!ignore_escaping && p[0] == _T('$') && p[1] == _T('\\'))
{
switch (p[2])
{
case _T('"'):
case _T('\''):
case _T('`'):

View file

@ -364,11 +364,18 @@ int CEXEBuild::doParse(const TCHAR *str)
// if ignoring, ignore all lines that don't begin with an exclamation mark
{
bool ignore_line = cur_ifblock && (cur_ifblock->ignore || cur_ifblock->inherited_ignore);
TCHAR first_char = *(TCHAR *) m_linebuild.get();
if (ignore_line && (first_char!=_T('!') || !is_ppbranch_token(line.gettoken_str(0))))
if (ignore_line)
{
m_linebuild.resize(0);
return PS_OK;
TCHAR *rawline = (TCHAR*) m_linebuild.get(), first_char = *rawline, buf[30], *first_token = buf;
if (!res)
first_token = line.gettoken_str(0);
else // LineParser::parse() failed so we cannot call gettoken_str but we still might need to ignore this line
for (size_t i = 0; i < COUNTOF(buf); ++i) if ((buf[i] = rawline[i]) <= ' ') { buf[i] = _T('\0'); break; }
if (first_char!=_T('!') || !is_ppbranch_token(first_token))
{
m_linebuild.resize(0);
return PS_OK;
}
}
}

View file

@ -329,7 +329,7 @@ void CEXEBuild::print_help(const TCHAR *commandname)
}
bool CEXEBuild::is_ppbranch_token(TCHAR *s)
bool CEXEBuild::is_ppbranch_token(const TCHAR *s)
{
int np, op, pos, tkid = get_commandtoken(s, &np, &op, &pos);
switch(tkid)