diff --git a/clang/lib/Edit/EditedSource.cpp b/clang/lib/Edit/EditedSource.cpp index a5b5875b19db..e557de92410e 100644 --- a/clang/lib/Edit/EditedSource.cpp +++ b/clang/lib/Edit/EditedSource.cpp @@ -295,9 +295,11 @@ static void adjustRemoval(const SourceManager &SM, const LangOptions &LangOpts, } if (buffer[end] == ' ') { + assert((end + 1 != buffer.size() || buffer.data()[end + 1] == 0) && + "buffer not zero-terminated!"); if (canRemoveWhitespace(/*left=*/buffer[begin-1], /*beforeWSpace=*/buffer[end-1], - /*right=*/buffer[end+1], + /*right=*/buffer.data()[end + 1], // zero-terminated LangOpts)) ++len; return; diff --git a/clang/test/FixIt/fixit-eof-space.c b/clang/test/FixIt/fixit-eof-space.c new file mode 100644 index 000000000000..dc9a45d0c52a --- /dev/null +++ b/clang/test/FixIt/fixit-eof-space.c @@ -0,0 +1,9 @@ +// RUN: not %clang_cc1 %s -fsyntax-only -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s +// vim: set binary noeol: + +// This file intentionally ends without a \n on the last line. Make sure your +// editor doesn't add one. The trailing space is also intentional. + +// CHECK: :9:8: warning: duplicate 'extern' declaration specifier +// CHECK: fix-it:"{{.*}}":{9:8-9:15}:"" +extern extern \ No newline at end of file