Skip to content

Commit 6fcfe7f

Browse files
committed
[CursorInfo] Don’t crash if we are performing cursor info at EOF
When performing code completion at the end of a file, the IDE inspection target would point to the null byte terminating the end of the string. That would cause us to consider this null byte as a code completion marker. When continuing to scan for the actual EOF, we would walk past the end of the buffer. Simply don’t consider the last null byte as a candidate for the code completion marker to fix the problem.
1 parent db14ae8 commit 6fcfe7f

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/Parse/Lexer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void Lexer::initialize(unsigned Offset, unsigned EndOffset) {
214214
// inserted to mark the code completion token. If the IDE inspection offset
215215
// points to a normal character, no code completion token should be
216216
// inserted.
217-
if (Ptr >= BufferStart && Ptr <= BufferEnd && *Ptr == '\0') {
217+
if (Ptr >= BufferStart && Ptr < BufferEnd && *Ptr == '\0') {
218218
CodeCompletionPtr = Ptr;
219219
}
220220
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// RUN: %sourcekitd-test -req=cursor -pos=2:1 %s -- %s

0 commit comments

Comments
 (0)