Fix crash on typing "#include " (#446)

* fix: scan include name until end of line

* fix: correctly check file existance

Co-authored-by: Dmitry Polshakov <dmitry.polshakov@dsr-corporation.com>
This commit is contained in:
Polshakov Dmitry 2022-02-18 15:32:05 +03:00 committed by GitHub
parent 6c8b75a05f
commit 39cc845df3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -50,7 +50,7 @@ namespace hex::pl {
offset += 1;
std::string includeFile;
while (code[offset] != endChar) {
while (code[offset] != endChar && code[offset] != '\n') {
includeFile += code[offset];
offset += 1;
@ -63,20 +63,24 @@ namespace hex::pl {
if (includeFile[0] != '/') {
for (const auto &dir : hex::getPath(ImHexPath::PatternsInclude)) {
fs::path tempPath = dir / includePath;
if (fs::exists(tempPath)) {
fs::path tempPath = dir / includePath;
if (fs::is_regular_file(tempPath)) {
includePath = tempPath;
break;
}
}
}
if (!fs::is_regular_file(includePath)) {
if (includePath.parent_path().filename().string() == "std")
throwPreprocessorError(hex::format("{0}: No such file.\n\nThis file might be part of the standard library.\nYou can install the standard library though\nthe Content Store found under Help -> Content Store.", includeFile.c_str()), lineNumber);
else
throwPreprocessorError(hex::format("{0}: No such file", includeFile.c_str()), lineNumber);
}
File file(includePath, File::Mode::Read);
if (!file.isValid()) {
if (includePath.parent_path().filename().string() == "std")
throwPreprocessorError(hex::format("{0}: No such file or directory.\n\nThis file might be part of the standard library.\nYou can install the standard library though\nthe Content Store found under Help -> Content Store.", includeFile.c_str()), lineNumber);
else
throwPreprocessorError(hex::format("{0}: No such file or directory", includeFile.c_str()), lineNumber);
throwPreprocessorError(hex::format("{0}: Failed to open file", includeFile.c_str()), lineNumber);
}
Preprocessor preprocessor;