From: Benjamin Kramer Date: Sun, 29 Mar 2015 18:07:29 +0000 (+0000) Subject: [edit] Don't hit an assert when trying to delete a trailing space at EOF X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=95871f43bf7d19f90bfe8a953e7bbe13b753081e;p=clang [edit] Don't hit an assert when trying to delete a trailing space at EOF The buffer is guaranteed to be zero-terminated so we can just circumvent the check. Found by afl-fuzz. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233496 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Edit/EditedSource.cpp b/lib/Edit/EditedSource.cpp index a5b5875b19..e557de9241 100644 --- a/lib/Edit/EditedSource.cpp +++ b/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/test/FixIt/fixit-eof-space.c b/test/FixIt/fixit-eof-space.c new file mode 100644 index 0000000000..dc9a45d0c5 --- /dev/null +++ b/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