Removed bogus comment about possible string prefix bug
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6491 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
8ed10146ef
commit
5574a0e7a2
1 changed files with 99 additions and 115 deletions
214
Source/build.cpp
214
Source/build.cpp
|
@ -603,142 +603,126 @@ int CEXEBuild::preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage/*=CP
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// starts with a $ but not $$.
|
// starts with a $ but not $$.
|
||||||
{ // block - why do we need this extra {?
|
bool bProceced=false;
|
||||||
bool bProceced=false;
|
if ( *p )
|
||||||
if ( *p )
|
{
|
||||||
|
const TCHAR *pUserVarName = p;
|
||||||
|
while (isSimpleChar(*pUserVarName))
|
||||||
|
pUserVarName++;
|
||||||
|
|
||||||
|
while (pUserVarName > p)
|
||||||
{
|
{
|
||||||
const TCHAR *pUserVarName = p;
|
if (m_ShellConstants.get(p, BUGBUG64TRUNCATE(int, pUserVarName-p)) >= 0)
|
||||||
while (isSimpleChar(*pUserVarName))
|
break; // Woops it's a shell constant
|
||||||
pUserVarName++;
|
|
||||||
|
|
||||||
while (pUserVarName > p)
|
int idxUserVar = m_UserVarNames.get(p, BUGBUG64TRUNCATE(int, pUserVarName-p));
|
||||||
|
if (idxUserVar >= 0)
|
||||||
{
|
{
|
||||||
if (m_ShellConstants.get(p, BUGBUG64TRUNCATE(int, pUserVarName-p)) >= 0)
|
// Well, using variables inside string formating doens't mean
|
||||||
break; // Woops it's a shell constant
|
// using the variable, because it will be always an empty string
|
||||||
|
// which is also memory wasting
|
||||||
// Jim Park: The following line could be a source of bugs for
|
// So the line below must be commented !??
|
||||||
// variables where one variable name is a prefix of another
|
//m_UserVarNames.inc_reference(idxUserVar);
|
||||||
// variable name. For example, if you are searching for
|
*out++ = (TCHAR) NS_VAR_CODE; // Named user variable;
|
||||||
// variable 'UserVar', you can get 'UserVariable' instead.
|
WORD w = FIX_ENDIAN_INT16(CODE_SHORT(idxUserVar));
|
||||||
// Suggest that we do:
|
unsigned int w4 = sizeof(TCHAR) > 2 ? FIX_ENDIAN_INT32(CODE_SHORT(idxUserVar)) : w; // Maybe this is too much endian fixing?
|
||||||
// TCHAR varname[NSIS_MAX_STRLEN];
|
if (sizeof(TCHAR) < 2) *((WORD*)out) = w, out += 2; else *out = (TCHAR) w4, out++;
|
||||||
// _tcsncpy(varname, p, pUserVarName-p);
|
p += pUserVarName-p; // zip past the user var string.
|
||||||
// int idxUserVar = m_UserVarNames.get(varname);
|
bProceced = true;
|
||||||
int idxUserVar = m_UserVarNames.get(p, BUGBUG64TRUNCATE(int, pUserVarName-p));
|
break;
|
||||||
if (idxUserVar >= 0)
|
|
||||||
{
|
|
||||||
// Well, using variables inside string formating doens't mean
|
|
||||||
// using the variable, beacuse it will be always an empty string
|
|
||||||
// which is also memory wasting
|
|
||||||
// So the line below must be commented !??
|
|
||||||
//m_UserVarNames.inc_reference(idxUserVar);
|
|
||||||
*out++ = (TCHAR) NS_VAR_CODE; // Named user variable;
|
|
||||||
WORD w = FIX_ENDIAN_INT16(CODE_SHORT(idxUserVar));
|
|
||||||
unsigned int w4 = sizeof(TCHAR) > 2 ? FIX_ENDIAN_INT32(CODE_SHORT(idxUserVar)) : w; // Maybe this is too much endian fixing?
|
|
||||||
if (sizeof(TCHAR) < 2) *((WORD*)out) = w, out += 2; else *out = (TCHAR) w4, out++;
|
|
||||||
p += pUserVarName-p; // zip past the user var string.
|
|
||||||
bProceced = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pUserVarName--;
|
|
||||||
}
|
}
|
||||||
}// if ( *p )
|
pUserVarName--;
|
||||||
if (!bProceced && *p)
|
}
|
||||||
|
}// if ( *p )
|
||||||
|
if (!bProceced && *p)
|
||||||
|
{
|
||||||
|
const TCHAR *pShellConstName = p;
|
||||||
|
while (isSimpleChar(*pShellConstName))
|
||||||
|
pShellConstName++;
|
||||||
|
|
||||||
|
while (pShellConstName > p)
|
||||||
{
|
{
|
||||||
const TCHAR *pShellConstName = p;
|
// Look for the identifier in the shell constants list of strings.
|
||||||
while (isSimpleChar(*pShellConstName))
|
int idxConst = m_ShellConstants.get((TCHAR*)p, BUGBUG64TRUNCATE(int, pShellConstName - p));
|
||||||
pShellConstName++;
|
|
||||||
|
|
||||||
while (pShellConstName > p)
|
// If found...
|
||||||
|
if (idxConst >= 0)
|
||||||
{
|
{
|
||||||
// Look for the identifier in the shell constants list of strings.
|
init_shellconstantvalues();
|
||||||
int idxConst = m_ShellConstants.get((TCHAR*)p, BUGBUG64TRUNCATE(int, pShellConstName - p));
|
int CSIDL_Value_current = m_ShellConstants.get_value1(idxConst);
|
||||||
|
int CSIDL_Value_all = m_ShellConstants.get_value2(idxConst);
|
||||||
// If found...
|
*out++=(TCHAR)NS_SHELL_CODE; // Constant code identifier
|
||||||
if (idxConst >= 0)
|
|
||||||
{
|
|
||||||
init_shellconstantvalues();
|
|
||||||
int CSIDL_Value_current = m_ShellConstants.get_value1(idxConst);
|
|
||||||
int CSIDL_Value_all = m_ShellConstants.get_value2(idxConst);
|
|
||||||
*out++=(TCHAR)NS_SHELL_CODE; // Constant code identifier
|
|
||||||
#ifdef _UNICODE
|
#ifdef _UNICODE
|
||||||
*out++=MAKEWORD(CSIDL_Value_current, CSIDL_Value_all);
|
*out++=MAKEWORD(CSIDL_Value_current, CSIDL_Value_all);
|
||||||
#else
|
#else
|
||||||
*out++=(TCHAR)CSIDL_Value_current;
|
*out++=(TCHAR)CSIDL_Value_current;
|
||||||
*out++=(TCHAR)CSIDL_Value_all;
|
*out++=(TCHAR)CSIDL_Value_all;
|
||||||
#endif
|
#endif
|
||||||
p = pShellConstName; // zip past the shell constant string.
|
p = pShellConstName; // zip past the shell constant string.
|
||||||
bProceced = true;
|
bProceced = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are looking from the longest identifier first and work
|
// We are looking from the longest identifier first and work
|
||||||
// smaller.
|
// smaller.
|
||||||
pShellConstName--;
|
pShellConstName--;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ( !bProceced && *p == _T('(') )
|
}
|
||||||
|
if ( !bProceced && *p == _T('(') )
|
||||||
|
{
|
||||||
|
int idx = -1;
|
||||||
|
TCHAR *cp = _tcsdup(p+1); // JP: Bad... should avoid memory alloc.
|
||||||
|
TCHAR *pos = _tcschr(cp, _T(')'));
|
||||||
|
if (pos)
|
||||||
{
|
{
|
||||||
int idx = -1;
|
*pos = 0;
|
||||||
TCHAR *cp = _tcsdup(p+1); // JP: Bad... should avoid memory alloc.
|
idx = DefineLangString(cp);
|
||||||
TCHAR *pos = _tcschr(cp, _T(')'));
|
if (idx < 0)
|
||||||
if (pos)
|
|
||||||
{
|
{
|
||||||
*pos = 0;
|
*out++ = (TCHAR)NS_LANG_CODE; // Next word is lang-string Identifier
|
||||||
idx = DefineLangString(cp);
|
WORD w = FIX_ENDIAN_INT16(CODE_SHORT(-idx-1));
|
||||||
if (idx < 0)
|
unsigned int w4 = sizeof(TCHAR) > 2 ? FIX_ENDIAN_INT32(CODE_SHORT(-idx-1)) : w; // Maybe this is too much endian fixing?
|
||||||
{
|
if (sizeof(TCHAR) < 2) *((WORD*)out) = w, out += 2; else *out = (TCHAR) w4, out++;
|
||||||
*out++ = (TCHAR)NS_LANG_CODE; // Next word is lang-string Identifier
|
p += _tcslen(cp) + 2;
|
||||||
WORD w = FIX_ENDIAN_INT16(CODE_SHORT(-idx-1));
|
bProceced = true;
|
||||||
unsigned int w4 = sizeof(TCHAR) > 2 ? FIX_ENDIAN_INT32(CODE_SHORT(-idx-1)) : w; // Maybe this is too much endian fixing?
|
}
|
||||||
if (sizeof(TCHAR) < 2) *((WORD*)out) = w, out += 2; else *out = (TCHAR) w4, out++;
|
}
|
||||||
p += _tcslen(cp) + 2;
|
free(cp);
|
||||||
bProceced = true;
|
}
|
||||||
}
|
if ( bProceced )
|
||||||
|
continue; // outermost while
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TCHAR tbuf[64], cBracket = _T('\0');
|
||||||
|
bool bDoWarning = true;
|
||||||
|
|
||||||
|
if ( *p == _T('[') ) cBracket = _T(']');
|
||||||
|
else if ( *p == _T('(') ) cBracket = _T(')');
|
||||||
|
else if ( *p == _T('{') ) cBracket = _T('}');
|
||||||
|
|
||||||
|
my_strncpy(tbuf,p,COUNTOF(tbuf));
|
||||||
|
|
||||||
|
if ( cBracket != 0 )
|
||||||
|
{
|
||||||
|
if (_tcschr(tbuf,cBracket)) (_tcschr(tbuf,cBracket)+1)[0]=0;
|
||||||
|
if ( tbuf[0] == _T('{') && tbuf[_tcslen(tbuf)-1] == _T('}') )
|
||||||
|
{
|
||||||
|
TCHAR *tstIfDefine = _tcsdup(tbuf+1);
|
||||||
|
tstIfDefine[_tcslen(tstIfDefine)-1] = _T('\0');
|
||||||
|
bDoWarning = definedlist.find(tstIfDefine) == NULL;
|
||||||
|
// If it's a defined identifier, then don't warn.
|
||||||
}
|
}
|
||||||
free(cp);
|
|
||||||
}
|
}
|
||||||
if ( bProceced )
|
|
||||||
continue; // outermost while
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TCHAR tbuf[64];
|
if (_tcsstr(tbuf,_T(" "))) _tcsstr(tbuf,_T(" "))[0]=0;
|
||||||
TCHAR cBracket = _T('\0');
|
|
||||||
bool bDoWarning = true;
|
|
||||||
|
|
||||||
if ( *p == _T('[') )
|
|
||||||
cBracket = _T(']');
|
|
||||||
else if ( *p == _T('(') )
|
|
||||||
cBracket = _T(')');
|
|
||||||
else if ( *p == _T('{') )
|
|
||||||
cBracket = _T('}');
|
|
||||||
|
|
||||||
my_strncpy(tbuf,p,COUNTOF(tbuf));
|
|
||||||
|
|
||||||
if ( cBracket != 0 )
|
|
||||||
{
|
|
||||||
if (_tcschr(tbuf,cBracket)) (_tcschr(tbuf,cBracket)+1)[0]=0;
|
|
||||||
if ( tbuf[0] == _T('{') && tbuf[_tcslen(tbuf)-1] == _T('}') )
|
|
||||||
{
|
|
||||||
TCHAR *tstIfDefine = _tcsdup(tbuf+1);
|
|
||||||
tstIfDefine[_tcslen(tstIfDefine)-1] = _T('\0');
|
|
||||||
bDoWarning = definedlist.find(tstIfDefine) == NULL;
|
|
||||||
// If it's a defined identifier, then don't warn.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_tcsstr(tbuf,_T(" "))) _tcsstr(tbuf,_T(" "))[0]=0;
|
|
||||||
}
|
|
||||||
if ( bDoWarning )
|
|
||||||
warning_fl(_T("unknown variable/constant \"%") NPRIs _T("\" detected, ignoring"),tbuf);
|
|
||||||
i = _T('$'); // redundant since i is already '$' and has
|
|
||||||
// not changed.
|
|
||||||
}
|
}
|
||||||
} // block
|
if ( bDoWarning )
|
||||||
|
warning_fl(_T("unknown variable/constant \"%") NPRIs _T("\" detected, ignoring"),tbuf);
|
||||||
|
i = _T('$'); // redundant since i is already '$' and has not changed.
|
||||||
|
}
|
||||||
} // else
|
} // else
|
||||||
} // else if (i == _T('$'))
|
} // else if (i == _T('$'))
|
||||||
|
|
||||||
*out++=(TCHAR)i;
|
*out++=(TCHAR)i;
|
||||||
} // outside while
|
} // outside while
|
||||||
*out=0;
|
*out=0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue