mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SourceKit] Add defensive guard for invalid offset
Invalid offset used to cause a inifinite loop in Lexer in some race condition. This is a quick fix until we fix underlying problem in SourceKit.
This commit is contained in:
@@ -496,6 +496,11 @@ void walkRelatedDecls(const ValueDecl *VD, const FnTy &Fn) {
|
||||
static StringRef getSourceToken(unsigned Offset,
|
||||
ImmutableTextSnapshotRef Snap) {
|
||||
auto MemBuf = Snap->getBuffer()->getInternalBuffer();
|
||||
|
||||
// FIXME: Invalid offset shouldn't reach here.
|
||||
if (Offset >= MemBuf->getBufferSize())
|
||||
return StringRef();
|
||||
|
||||
SourceManager SM;
|
||||
auto MemBufRef = llvm::MemoryBuffer::getMemBuffer(MemBuf->getBuffer(),
|
||||
MemBuf->getBufferIdentifier());
|
||||
|
||||
Reference in New Issue
Block a user