On Thu, Dec 12, 2013 at 07:01:18PM -0600, Joshua Cranmer ? wrote: > On 12/12/2013 6:52 PM, David Keeler wrote: > >Recently bug 539710 landed[0] to fix an unnecessary and apparently > >unsafe operation: > > > >const PRUnichar *comma = NS_LITERAL_STRING(",").get(); > > > >Curious, I did a quick search for other examples of NS_LITERAL_STRING > >combined with .get() and found that this appears to be common[1]. > >So, I have a few questions for anyone with some insight: > >- Is this pattern always unsafe? > >- Is it sometimes unsafe? (if so, when/why?) > > NS_LITERAL_STRING creates a temporary object that is cleaned up at > the end of the statement. So it's a safe pattern for passing as an > argument to a function, but not for initializing a variable.
certainly theoretically unsafe, but I'd expect practically its fine. > >- Should we do some cleanup and avoid things like this? (or maybe this > >is an outdated concern and isn't an issue anymore?) > > Given that PRUnichar is now unconditionally typedef'd to our version > of char16_t (and the patch has landed for a long while without being > backed out yet), I think we should now be able to use MOZ_UTF16(",") > instead of NS_LITERAL_STRING(",").get(). MOZ_UTF16 is basically a > choice between using L"" or U"" depending on compiler support for > char16_t and thus is always safe. yeah, I just ran sed -i 's/NS_LITERAL_STRING("\(.*\)").get()/MOZ_UTF16("\1")/' $(find -name *.cpp) and the same for *.h and *.cc I'm building it now. Trev > > -- > Joshua Cranmer > Thunderbird and DXR developer > Source code archæologist > > _______________________________________________ > dev-platform mailing list > dev-platform@lists.mozilla.org > https://lists.mozilla.org/listinfo/dev-platform _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform