[cfe-dev] createCXString reads one past end byte

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Jan 22 11:29:27 PST 2013


On Jan 22, 2013, at 6:49 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:

> Hello Argyrios,
> 
> On Mon, Jan 21, 2013 at 9:13 PM, Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:
>> We could change how CXString works; instead of eagerly malloc'ing in case of a StringRef, have it stored in a "StringRef-kind" form and malloc when clang_getCString is called.
> 
> This will add an extra backing storage mode to CXString, let's call
> that CXS_UnmanagedWithLength.  In this mode we will store the pointer
> in 'data', and length will be stored in the upper bits of
> 'private_flags'.  But who will own the memory returned by
> clang_getCString?  We can not change the original CXString from
> CXS_UnmanagedWithLength to CXS_Malloc because CXString is a value
> type.  Or did I misunderstand something?

You are right, it is so easy to get a copy of it and trigger a memory leak unintentionally.

I'll do some measurements to see if it makes much difference to malloc on every StringRef (in the meantime any suggestions on how to avoid the malloc would be greatly appreciated).

-Argyrios

> 
> Dmitri
> 
> -- 
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/





More information about the cfe-dev mailing list