[cfe-dev] graphviz problem

Ted Kremenek kremenek at apple.com
Tue Nov 11 19:06:08 PST 2008


It's a subtle detail.  Maybe we should wrap the return value of  
getStrData() with a variant so people won't repeatedly make the same  
mistake (this comment is very easy to miss).

Incidentally, it's this way because a string literal can contain a  
null character anywhere in the literal.

e.g.

const char *s = "hello\0world";

On Nov 11, 2008, at 7:02 PM, Zhongxing Xu wrote:

> Thanks, Ted. I should read that comment.
>
> On Wed, Nov 12, 2008 at 10:52 AM, Ted Kremenek <kremenek at apple.com>  
> wrote:
> From Expr.h:
>
> /// StringLiteral - This represents a string literal expression,  
> e.g. "foo"
> /// or L"bar" (wide strings).  The actual string is returned by  
> getStrData()
> /// is NOT null-terminated, and the length of the string is  
> determined by
> /// calling getByteLength().  The C type for a string is always a
> /// ConstantArrayType.
>
> This means that using strlen(StringLiteral::getStrData()) is not  
> safe; it will just march off the end of the literal until it hits  
> the first null character that lies on the heap.
>
> On Nov 11, 2008, at 6:02 PM, Zhongxing Xu wrote:
>
>> Did you use the fixed version? My observasion is that sometimes  
>> strlen(StringLiteral::getStrData()) is different from  
>> StringLiteral::getByteLength().
>>
>> On Tue, Nov 11, 2008 at 11:47 PM, Nuno Lopes <nunoplopes at sapo.pt>  
>> wrote:
>> Here it works just fine. But my system's default charset is latin0  
>> (similar with latin1).
>> Nuno
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20081111/df71892a/attachment.html>


More information about the cfe-dev mailing list