From fd0ca976bd55167364ba1178e884d275cc6ef30b Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 14 Jan 2013 16:02:06 +0000 Subject: [PATCH] Fix a bug in the line merging. 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 | 2 ++ unittests/Format/FormatTest.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 742b9a8d1c..4e9fd405df 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index daebc4ddab..8e55ddb5d0 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) { -- 2.40.0