]> granicus.if.org Git - clang/commitdiff
Fix a bug in the line merging.
authorDaniel Jasper <djasper@google.com>
Mon, 14 Jan 2013 16:02:06 +0000 (16:02 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 14 Jan 2013 16:02:06 +0000 (16:02 +0000)
If the first line of a merge would exactly fit into the column limit,
an unsigned overflow made us not break.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172426 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 742b9a8d1cc7a734aa1635702cb7673db28aec6d..4e9fd405df32ee420a279e276c2b16d831de88ba 100644 (file)
@@ -1408,6 +1408,8 @@ private:
     unsigned Length = 0;
     if (!fitsIntoLimit(I->First, Limit, &Length))
       return false;
+    if (Limit == Length)
+      return true; // Couldn't fit a space.
     Limit -= Length + 1; // One space.
     if (I + 1 == E)
       return true;
index daebc4ddab1a5a5350b6d57a3922f1ab2212711e..8e55ddb5d0fc6ed489e8b3a965213b66ddb98db8 100644 (file)
@@ -138,6 +138,8 @@ TEST_F(FormatTest, FormatIfWithoutCompountStatement) {
                "  f();");
   verifyFormat("if (a) return;", getLLVMStyleWithColumns(14));
   verifyFormat("if (a)\n  return;", getLLVMStyleWithColumns(13));
+  verifyFormat("if (aaaaaaaaa)\n"
+               "  return;", getLLVMStyleWithColumns(14));
 }
 
 TEST_F(FormatTest, ParseIfElse) {