From 10a7bd634117e66420d457b601a7357a10a1ed97 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 23 May 2008 23:29:33 +0000 Subject: [PATCH] fix a nasty off-by-one error. llvm-svn: 51519 --- clang/lib/Rewrite/RewriteRope.cpp | 2 +- clang/test/Rewriter/crash.m | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 clang/test/Rewriter/crash.m diff --git a/clang/lib/Rewrite/RewriteRope.cpp b/clang/lib/Rewrite/RewriteRope.cpp index 9d5d7a741053..f1fd3f7ba971 100644 --- a/clang/lib/Rewrite/RewriteRope.cpp +++ b/clang/lib/Rewrite/RewriteRope.cpp @@ -578,7 +578,7 @@ void RopePieceBTreeInterior::erase(unsigned Offset, unsigned NumBytes) { NumBytes -= CurChild->size(); CurChild->Destroy(); --NumChildren; - if (i+1 != getNumChildren()) + if (i != getNumChildren()) memmove(&Children[i], &Children[i+1], (getNumChildren()-i)*sizeof(Children[0])); } diff --git a/clang/test/Rewriter/crash.m b/clang/test/Rewriter/crash.m new file mode 100644 index 000000000000..59f18f37c2c9 --- /dev/null +++ b/clang/test/Rewriter/crash.m @@ -0,0 +1,14 @@ +// RUN: clang -rewrite-objc -o - %s +// rdar://5950938 +@interface NSArray {} ++ (id)arrayWithObjects:(id)firstObj, ...; +@end + +@interface NSConstantString {} +@end + +int main() { + id foo = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", 0]; + return 0; +} +