From: Craig Topper Date: Tue, 26 May 2015 08:07:49 +0000 (+0000) Subject: [TableGen] Rewrite an assert to not do a bunch unsigned math and then try to ensure... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=c9739ec212365e5197eb87cb3a50d256df626dc4 [TableGen] Rewrite an assert to not do a bunch unsigned math and then try to ensure the result is a positive number. I think the fact that it was explicitly excluding 0 kept this from being a tautology. The exclusion of 0 for the old math was also a bug that's easily hit if the description gets split into multiple lines. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238186 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/TableGen/TableGenBackend.cpp b/lib/TableGen/TableGenBackend.cpp index 9763f85c793..43f8cb089ec 100644 --- a/lib/TableGen/TableGenBackend.cpp +++ b/lib/TableGen/TableGenBackend.cpp @@ -22,11 +22,11 @@ const size_t MAX_LINE_LEN = 80U; static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill, StringRef Suffix) { size_t Pos = (size_t)OS.tell(); - assert((MAX_LINE_LEN - Prefix.str().size() - Suffix.size() > 0) && + assert((Prefix.str().size() + Suffix.size() <= MAX_LINE_LEN) && "header line exceeds max limit"); OS << Prefix; - const size_t e = MAX_LINE_LEN - Suffix.size(); - for (size_t i = (size_t)OS.tell() - Pos; i < e; ++i) + for (size_t i = (size_t)OS.tell() - Pos, e = MAX_LINE_LEN - Suffix.size(); + i < e; ++i) OS << Fill; OS << Suffix << '\n'; }