[cfe-dev] sizeof (RopeRefCountString)

Zhongxing Xu xuzhongxing at gmail.com
Mon Sep 15 22:17:13 PDT 2008


May I commit the patch:

Index: lib/Rewrite/RewriteRope.cpp
===================================================================
--- lib/Rewrite/RewriteRope.cpp (revision 56235)
+++ lib/Rewrite/RewriteRope.cpp (working copy)
@@ -792,7 +792,7 @@
   if (AllocBuffer && --AllocBuffer->RefCount == 0)
     delete [] (char*)AllocBuffer;

-  unsigned AllocSize = sizeof(RopeRefCountString)-1+AllocChunkSize;
+  unsigned AllocSize = offsetof(RopeRefCountString, Data) + AllocChunkSize;
   AllocBuffer = reinterpret_cast<RopeRefCountString *>(new
char[AllocSize]);
   AllocBuffer->RefCount = 0;
   memcpy(AllocBuffer->Data, Start, Len);


2008/9/16 Ted Kremenek <kremenek at apple.com>

>
> On Sep 15, 2008, at 9:41 PM, Daniel Dunbar wrote:
>
>  #include <stddef.h>
>>
>> unsigned AllocSize = sizeof(RopeRefCountString) -
>> offsetof(RopeRefCountString,Data) + AllocChunkSize;
>>
>
> I don't think that's right.  sizeof(RopeRefCountString) -
> offsetof(RopeRefCountString,Data) is 4.  What we want is the number of bytes
> before "data", not after (inclusive).
>
> Probably:
>
>  offsetof(RopeRefCountString,Data) + AllocChunkSize
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080916/c871e26e/attachment.html>


More information about the cfe-dev mailing list