[Libreoffice] Removal of rtl::O[U]String[Buffer]::operator sal_{char|Unicode} const *()

Stephan Bergmann sbergman at redhat.com
Wed Oct 5 00:27:56 PDT 2011

On 09/27/2011 09:00 PM, Stephan Bergmann wrote:
> Hi all,
> As has recently been discussed on #libreoffice-dev, its probably a good
> idea to remove the rather unhelpful conversion operators
> rtl::OString::operator sal_Char const * ()
> rtl::OStringBuffer::operator sal_Char const * ()
> rtl::OUString::operator sal_Unicode const * ()
> rtl::OUStringBuffer::operator sal_Unicode const * ()
> (The reason why this came up on IRC this time was that the expression
> "aStr = aStr + cSep" with aStr of type rtl::OString and cSep of type
> sal_Char had a rather non-intuitive meaning, implicitly converting aStr
> into a sal_Char const *, adding the integral value of cSep to that
> pointer, and then converting that modified sal_Char const * back into an
> rtl::OString via the rtl::OString(sal_Char const *) constructor.)
> The change will be source-code incompatible, but that is probably
> acceptable:
> - The change is ABI compatible (involving only inline C++ functions).
> - The ~only legitimate use case for those conversion operators was in
> indexing expressions like aStr[n]. To continue those expressions to
> work, appropriate operator [](sal_Int) member functions will be added to
> the four classes.
> - All other uses of the conversion operators should use the getStr()
> member functions. (Also note that there might be cases where translation
> between, say, rtl::OString and char const * via naive application of
> rtl::OString::getStr() is not appropriate as it potentially looses
> information, when the given rtl::OString instance contains NUL
> characters. Having the calls to getStr explicitly in the code helps
> auditing in this case.)
> My plan is as follows:
> - I just pushed
> <http://cgit.freedesktop.org/libreoffice/core/commit/?id=6671fa81db0ecea4ada005bb79f55f08fb440ad4>
> "Removed uses of rtl::O[U]String[Buffer]::operator sal_{char|Unicode}
> const *()." and
> <http://cgit.freedesktop.org/libreoffice/binfilter/commit/?id=34c2ec87db4b6962ded661157056c58163e39821>
> "Removed uses of rtl::O[U]String[Buffer]::operator sal_{char|Unicode}
> const *()." That clears the current master of all dubious (i.e., non-[])
> uses of the conversion operators for a Linux x86_64 --enable-binfilter
> --enable-dbgutil "make check" build.
> - A few more builds (e.g., Windows, Mac OS X) should be done with the
> below patch to ensure that as many dubious uses in
> platform-/configuration-switch-specific code as possible have been
> fixed. If someone wants to give me a hand here, that would be great.

Decided to push 
"Removed dangerous rtl::O[U]String[Buffer]::operator sal_{char,Unicode} 
const *." now, even though I didn't manage to get a Windows build yet 
(and it looks like that will still take a while...).

So, if you build on Windows and experience a breaker due to this commit, 
please be so kind and fix it (or discuss it here).


More information about the LibreOffice mailing list