]> granicus.if.org Git - clang/commitdiff
fix a rewriter crash on zero length files.
authorChris Lattner <sabre@nondot.org>
Wed, 23 Apr 2008 03:21:50 +0000 (03:21 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 23 Apr 2008 03:21:50 +0000 (03:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50126 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Rewrite/RewriteRope.h
lib/Rewrite/RewriteRope.cpp

index 10ce4432cec8592bebe17c8b7a59d0ebd4b15b2c..963c0715d905d5e5bdfdc6eeb998164343274888 100644 (file)
@@ -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) {
index db55aa1cd4d89bfb74942d81d406fb6ce9b1b777..7ee9fcced242aaef444ecd349dfae639dc1c2e21 100644 (file)
@@ -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) {