<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">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).<div><br></div><div>Incidentally, it's this way because a string literal can contain a null character anywhere in the literal.</div><div><br></div><div>e.g.</div><div><br></div><div>const char *s = "hello\0world";</div><div><br><div><div>On Nov 11, 2008, at 7:02 PM, Zhongxing Xu wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Thanks, Ted. I should read that comment.<br><br><div class="gmail_quote">On Wed, Nov 12, 2008 at 10:52 AM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <div style="">From Expr.h:<div><br></div><div><div>/// StringLiteral - This represents a string literal expression, e.g. "foo"</div> <div>/// or L"bar" (wide strings).  The actual string is returned by getStrData()</div> <div>/// is NOT null-terminated, and the length of the string is determined by</div> <div>/// calling getByteLength().  The C type for a string is always a</div> <div>/// ConstantArrayType.</div><div><br></div><div>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.</div> <div><br><div><div><div></div><div class="Wj3C7c"><div>On Nov 11, 2008, at 6:02 PM, Zhongxing Xu wrote:</div><br></div></div><blockquote type="cite"><div><div></div><div class="Wj3C7c">Did you use the fixed version? My observasion is that sometimes strlen(StringLiteral::getStrData()) is different from StringLiteral::getByteLength().<br> <br><div class="gmail_quote">On Tue, Nov 11, 2008 at 11:47 PM, Nuno Lopes <span dir="ltr"><<a href="mailto:nunoplopes@sapo.pt" target="_blank">nunoplopes@sapo.pt</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Here it works just fine. But my system's default charset is latin0 (similar with latin1).<br><font color="#888888"> Nuno</font><div><div></div><div><br> </div></div></blockquote></div><br></div></div> _______________________________________________<br> cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br> </blockquote></div><br></div></div></div></blockquote></div><br></blockquote></div><br></div></body></html>