diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2012-04-02 16:52:36 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2012-04-02 16:58:13 +0200 |
commit | 60b596665fff7c110c6b12da192f5712fb145028 (patch) | |
tree | fa276f47afef1cf8d1226c56f82a40cd30b8e820 /sal | |
parent | a312d8a0a20add8cb6aecda4141e3cc299c1ffbc (diff) |
warn on \0 embedded in string literals, after all
Seeing 791f27683311e487947b0464a0cb132b19fd0e12 I've changed my mind,
some embedded \0 can be actually well hidden:
struct foo { const char txt[3]; };
const foos[] = { { "a" }, { "bb" }};
If somebody wants an embedded \0 in a string literal, they need to
say it explicitly by specifying the size.
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/rtl/string.hxx | 4 | ||||
-rw-r--r-- | sal/inc/rtl/ustring.hxx | 3 | ||||
-rw-r--r-- | sal/rtl/source/strtmpl.cxx | 2 |
3 files changed, 8 insertions, 1 deletions
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx index 8dbb41373a1c..a00e1861aa8c 100644 --- a/sal/inc/rtl/string.hxx +++ b/sal/inc/rtl/string.hxx @@ -196,7 +196,9 @@ public: New string from a string literal. If there are any embedded \0's in the string literal, the result is undefined. - Use the overload that explicitly accepts length. + Use the overload that explicitly accepts length or cast the literal + explicitly to const char*. + @since LibreOffice 3.6 @param literal a string literal diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx index 8035bdc50252..518ef3d96625 100644 --- a/sal/inc/rtl/ustring.hxx +++ b/sal/inc/rtl/ustring.hxx @@ -190,6 +190,9 @@ public: is not pure ASCII, it needs to be converted to OUString by explicitly providing the encoding to use for the conversion. + If there are any embedded \0's in the string literal, the result is undefined. + Use the overload that explicitly accepts length or fromAscii(). + @param literal the 8-bit ASCII string literal @since LibreOffice 3.6 diff --git a/sal/rtl/source/strtmpl.cxx b/sal/rtl/source/strtmpl.cxx index 2a339079a89f..be86ab305d7a 100644 --- a/sal/rtl/source/strtmpl.cxx +++ b/sal/rtl/source/strtmpl.cxx @@ -1220,6 +1220,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromLiteral)( IMPL_RTL_STRINGDATA** ppThis /* Check ASCII range */ SAL_WARN_IF( ((unsigned char)*pCharStr) > 127, "rtl.string", "rtl_uString_newFromLiteral - Found char > 127" ); + SAL_WARN_IF( ((unsigned char)*pCharStr) == '\0', "rtl.string", + "rtl_uString_newFromLiteral - Found embedded \\0 character" ); *pBuffer = *pCharStr; pBuffer++; |