[cfe-dev] sizeof (RopeRefCountString)
Ted Kremenek
kremenek at apple.com
Mon Sep 15 22:45:55 PDT 2008
That looks good to me unless anyone has any objections. I assume it
passes "make test."
On Sep 15, 2008, at 10:17 PM, Zhongxing Xu wrote:
> 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/20080915/b22558c1/attachment.html>
More information about the cfe-dev
mailing list