Skip to content

Commit 245b749

Browse files
committed
Fix #14307 (Update simplecpp to 1.6.3)
1 parent 1c37d49 commit 245b749

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

externals/simplecpp/simplecpp.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ void simplecpp::TokenList::constFold()
984984
constFoldComparison(tok);
985985
constFoldBitwise(tok);
986986
constFoldLogicalOp(tok);
987-
constFoldQuestionOp(&tok);
987+
constFoldQuestionOp(tok);
988988

989989
// If there is no '(' we are done with the constant folding
990990
if (tok->op != '(')
@@ -1354,11 +1354,11 @@ void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
13541354
}
13551355
}
13561356

1357-
void simplecpp::TokenList::constFoldQuestionOp(Token **tok1)
1357+
void simplecpp::TokenList::constFoldQuestionOp(Token *&tok1)
13581358
{
13591359
bool gotoTok1 = false;
13601360
// NOLINTNEXTLINE(misc-const-correctness) - technically correct but used to access non-const data
1361-
for (Token *tok = *tok1; tok && tok->op != ')'; tok = gotoTok1 ? *tok1 : tok->next) {
1361+
for (Token *tok = tok1; tok && tok->op != ')'; tok = gotoTok1 ? tok1 : tok->next) {
13621362
gotoTok1 = false;
13631363
if (tok->str() != "?")
13641364
continue;
@@ -1373,8 +1373,8 @@ void simplecpp::TokenList::constFoldQuestionOp(Token **tok1)
13731373
Token * const falseTok = trueTok->next->next;
13741374
if (!falseTok)
13751375
throw std::runtime_error("invalid expression");
1376-
if (condTok == *tok1)
1377-
*tok1 = (condTok->str() != "0" ? trueTok : falseTok);
1376+
if (condTok == tok1)
1377+
tok1 = (condTok->str() != "0" ? trueTok : falseTok);
13781378
deleteToken(condTok->next); // ?
13791379
deleteToken(trueTok->next); // :
13801380
deleteToken(condTok->str() == "0" ? trueTok : falseTok);
@@ -3126,7 +3126,21 @@ bool simplecpp::FileDataCache::getFileId(const std::string &path, FileID &id)
31263126
if (hFile == INVALID_HANDLE_VALUE)
31273127
return false;
31283128

3129-
const BOOL ret = GetFileInformationByHandleEx(hFile, FileIdInfo, &id.fileIdInfo, sizeof(id.fileIdInfo));
3129+
BOOL ret = GetFileInformationByHandleEx(hFile, FileIdInfo, &id.fileIdInfo, sizeof(id.fileIdInfo));
3130+
if (!ret) {
3131+
const DWORD err = GetLastError();
3132+
if (err == ERROR_INVALID_PARAMETER || // encountered when using a non-NTFS filesystem e.g. exFAT
3133+
err == ERROR_NOT_SUPPORTED) // encountered on Windows Server Core (used as a Docker container)
3134+
{
3135+
BY_HANDLE_FILE_INFORMATION fileInfo;
3136+
ret = GetFileInformationByHandle(hFile, &fileInfo);
3137+
if (ret) {
3138+
id.fileIdInfo.VolumeSerialNumber = static_cast<std::uint64_t>(fileInfo.dwVolumeSerialNumber);
3139+
id.fileIdInfo.FileId.IdentifierHi = static_cast<std::uint64_t>(fileInfo.nFileIndexHigh);
3140+
id.fileIdInfo.FileId.IdentifierLo = static_cast<std::uint64_t>(fileInfo.nFileIndexLow);
3141+
}
3142+
}
3143+
}
31303144

31313145
CloseHandle(hFile);
31323146

@@ -3227,14 +3241,14 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
32273241
return cache;
32283242
}
32293243

3230-
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token **tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList *outputList)
3244+
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList *outputList)
32313245
{
3232-
const simplecpp::Token * const tok = *tok1;
3246+
const simplecpp::Token * const tok = tok1;
32333247
const simplecpp::MacroMap::const_iterator it = tok->name ? macros.find(tok->str()) : macros.end();
32343248
if (it != macros.end()) {
32353249
simplecpp::TokenList value(files);
32363250
try {
3237-
*tok1 = it->second.expand(value, tok, macros, files);
3251+
tok1 = it->second.expand(value, tok, macros, files);
32383252
} catch (const simplecpp::Macro::Error &err) {
32393253
if (outputList) {
32403254
simplecpp::Output out = {
@@ -3250,7 +3264,7 @@ static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token
32503264
} else {
32513265
if (!tok->comment)
32523266
output.push_back(new simplecpp::Token(*tok));
3253-
*tok1 = tok->next;
3267+
tok1 = tok->next;
32543268
}
32553269
return true;
32563270
}
@@ -3488,7 +3502,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
34883502
TokenList inc2(files);
34893503
if (!inc1.empty() && inc1.cfront()->name) {
34903504
const Token *inctok = inc1.cfront();
3491-
if (!preprocessToken(inc2, &inctok, macros, files, outputList)) {
3505+
if (!preprocessToken(inc2, inctok, macros, files, outputList)) {
34923506
output.clear();
34933507
return;
34943508
}
@@ -3657,7 +3671,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36573671
maybeUsedMacros[rawtok->next->str()].push_back(rawtok->next->location);
36583672

36593673
const Token *tmp = tok;
3660-
if (!preprocessToken(expr, &tmp, macros, files, outputList)) {
3674+
if (!preprocessToken(expr, tmp, macros, files, outputList)) {
36613675
output.clear();
36623676
return;
36633677
}
@@ -3755,7 +3769,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37553769
const Location loc(rawtok->location);
37563770
TokenList tokens(files);
37573771

3758-
if (!preprocessToken(tokens, &rawtok, macros, files, outputList)) {
3772+
if (!preprocessToken(tokens, rawtok, macros, files, outputList)) {
37593773
output.clear();
37603774
return;
37613775
}

externals/simplecpp/simplecpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ namespace simplecpp {
353353
void constFoldComparison(Token *tok);
354354
void constFoldBitwise(Token *tok);
355355
void constFoldLogicalOp(Token *tok);
356-
void constFoldQuestionOp(Token **tok1);
356+
void constFoldQuestionOp(Token *&tok1);
357357

358358
std::string readUntil(Stream &stream, const Location &location, char start, char end, OutputList *outputList);
359359
void lineDirective(unsigned int fileIndex, unsigned int line, Location *location);

0 commit comments

Comments
 (0)