зеркало из https://github.com/mozilla/pjs.git
Bug 506394 - ExpandEnvironmentStringsW in CE shunt isn't quite right, r=vlad
This commit is contained in:
Родитель
62af18f88c
Коммит
327a19dfc6
|
@ -198,43 +198,53 @@ SetEnvironmentVariableW(const unsigned short* name,
|
|||
|
||||
|
||||
unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc,
|
||||
unsigned short* lpDst,
|
||||
unsigned int nSize)
|
||||
unsigned short* lpDst,
|
||||
unsigned int nSize)
|
||||
{
|
||||
if ( NULL == lpDst )
|
||||
return 0;
|
||||
|
||||
|
||||
unsigned int size = 0;
|
||||
unsigned int index = 0;
|
||||
unsigned int origLen = wcslen(lpSrc);
|
||||
|
||||
const unsigned short *pIn = lpSrc;
|
||||
unsigned short *pOut = lpDst;
|
||||
|
||||
|
||||
while ( index < origLen ) {
|
||||
|
||||
|
||||
if (*pIn != L'%') { // Regular char, copy over
|
||||
if ( size < nSize ) *pOut = *pIn, pOut++;
|
||||
index++, size++, pIn++;
|
||||
if ( size++ < nSize ) *pOut = *pIn, pOut++;
|
||||
index++, pIn++;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Have a starting '%' - look for matching '%'
|
||||
int envlen = 0;
|
||||
const unsigned short *pTmp = ++pIn; // Move past original '%'
|
||||
while ( L'%' != *pTmp ) {
|
||||
const unsigned short *pTmp = pIn + 1;
|
||||
while ( *pTmp != L'%' && *pTmp != L' ' ) {
|
||||
envlen++, pTmp++;
|
||||
if ( origLen < index + envlen ) { // Ran past end of original
|
||||
SetLastError(ERROR_INVALID_PARAMETER); // buffer without matching '%'
|
||||
return -1;
|
||||
while ( envlen-- ) {
|
||||
if ( size++ < nSize ) *pOut = *pIn, pOut++;
|
||||
index++, pIn++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( *pTmp == L' ' ) { // Need to append through space
|
||||
while ( envlen-- ) {
|
||||
if ( size++ < nSize ) *pOut = *pIn, pOut++;
|
||||
index++, pIn++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
pIn++; // Move past original %
|
||||
if ( 0 == envlen ) { // Encountered a "%%" - mapping to "%"
|
||||
size++;
|
||||
if ( size < nSize ) *pOut = *pIn, pOut++;
|
||||
pIn++;
|
||||
index += 2;
|
||||
if ( size++ < nSize ) *pOut = *pIn, pOut++;
|
||||
index += 2, pIn++;
|
||||
} else {
|
||||
// Encountered a "%something%" - mapping "something"
|
||||
char key[256];
|
||||
|
@ -252,7 +262,7 @@ unsigned int ExpandEnvironmentStringsW(const unsigned short* lpSrc,
|
|||
pIn = ++pTmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( size < nSize ) lpDst[size] = 0;
|
||||
return size;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче