]> granicus.if.org Git - clang/commitdiff
[edit] Don't hit an assert when trying to delete a trailing space at EOF
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 29 Mar 2015 18:07:29 +0000 (18:07 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 29 Mar 2015 18:07:29 +0000 (18:07 +0000)
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

lib/Edit/EditedSource.cpp
test/FixIt/fixit-eof-space.c [new file with mode: 0644]

index a5b5875b19dbd91ddfbbb0882b464287d8c9b944..e557de92410ed2d81701cefef9905c9ed0d1b088 100644 (file)
@@ -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 (file)
index 0000000..dc9a45d
--- /dev/null
@@ -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