r233496 - [edit] Don't hit an assert when trying to delete a trailing space at EOF

Benjamin Kramer benny.kra at googlemail.com
Sun Mar 29 11:07:29 PDT 2015


Author: d0k
Date: Sun Mar 29 13:07:29 2015
New Revision: 233496

URL: http://llvm.org/viewvc/llvm-project?rev=233496&view=rev
Log:
[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.

Added:
    cfe/trunk/test/FixIt/fixit-eof-space.c
Modified:
    cfe/trunk/lib/Edit/EditedSource.cpp

Modified: cfe/trunk/lib/Edit/EditedSource.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/EditedSource.cpp?rev=233496&r1=233495&r2=233496&view=diff
==============================================================================
--- cfe/trunk/lib/Edit/EditedSource.cpp (original)
+++ cfe/trunk/lib/Edit/EditedSource.cpp Sun Mar 29 13:07:29 2015
@@ -295,9 +295,11 @@ static void adjustRemoval(const SourceMa
   }
 
   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;

Added: cfe/trunk/test/FixIt/fixit-eof-space.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-eof-space.c?rev=233496&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/fixit-eof-space.c (added)
+++ cfe/trunk/test/FixIt/fixit-eof-space.c Sun Mar 29 13:07:29 2015
@@ -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





More information about the cfe-commits mailing list