diff --git a/clang/lib/Index/IndexUnitReader.cpp b/clang/lib/Index/IndexUnitReader.cpp index 30e474d6d6165..a1f8ca7798407 100644 --- a/clang/lib/Index/IndexUnitReader.cpp +++ b/clang/lib/Index/IndexUnitReader.cpp @@ -378,10 +378,10 @@ void IndexUnitReaderImpl::constructFilePath(SmallVectorImpl &PathBuf, } StringRef IndexUnitReaderImpl::getModuleName(int ModuleIndex) { - if (ModuleIndex < 0) + if (ModuleIndex < 0 || ModuleNamesBuffer.empty()) return StringRef(); auto &ModInfo = Modules[ModuleIndex]; - return StringRef(ModuleNamesBuffer.data()+ModInfo.NameOffset, ModInfo.NameSize); + return ModuleNamesBuffer.substr(ModInfo.NameOffset, ModInfo.NameSize); }