From: Chris Lattner Date: Wed, 23 Apr 2008 03:21:50 +0000 (+0000) Subject: fix a rewriter crash on zero length files. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c66d0aa934f2afd412f50881a5e959bb8582cf14;p=clang fix a rewriter crash on zero length files. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50126 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Rewrite/RewriteRope.h b/include/clang/Rewrite/RewriteRope.h index 10ce4432ce..963c0715d9 100644 --- a/include/clang/Rewrite/RewriteRope.h +++ b/include/clang/Rewrite/RewriteRope.h @@ -204,7 +204,8 @@ public: void assign(const char *Start, const char *End) { clear(); - Chunks.insert(0, MakeRopeString(Start, End)); + if (Start != End) + Chunks.insert(0, MakeRopeString(Start, End)); } void insert(unsigned Offset, const char *Start, const char *End) { diff --git a/lib/Rewrite/RewriteRope.cpp b/lib/Rewrite/RewriteRope.cpp index db55aa1cd4..7ee9fcced2 100644 --- a/lib/Rewrite/RewriteRope.cpp +++ b/lib/Rewrite/RewriteRope.cpp @@ -741,6 +741,7 @@ void RopePieceBTree::erase(unsigned Offset, unsigned NumBytes) { /// allocation instead of doing tons of tiny allocations. RopePiece RewriteRope::MakeRopeString(const char *Start, const char *End) { unsigned Len = End-Start; + assert(Len && "Zero length RopePiece is invalid!"); // If we have space for this string in the current alloc buffer, use it. if (AllocOffs+Len <= AllocChunkSize) {