Kaydet (Commit) 60b59666 authored tarafından Luboš Luňák's avatar Luboš Luňák

warn on \0 embedded in string literals, after all

Seeing 791f2768 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.
üst a312d8a0
...@@ -196,7 +196,9 @@ public: ...@@ -196,7 +196,9 @@ public:
New string from a string literal. New string from a string literal.
If there are any embedded \0's in the string literal, the result is undefined. 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 @since LibreOffice 3.6
@param literal a string literal @param literal a string literal
......
...@@ -190,6 +190,9 @@ public: ...@@ -190,6 +190,9 @@ public:
is not pure ASCII, it needs to be converted to OUString by explicitly is not pure ASCII, it needs to be converted to OUString by explicitly
providing the encoding to use for the conversion. 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 @param literal the 8-bit ASCII string literal
@since LibreOffice 3.6 @since LibreOffice 3.6
......
...@@ -1220,6 +1220,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromLiteral)( IMPL_RTL_STRINGDATA** ppThis ...@@ -1220,6 +1220,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromLiteral)( IMPL_RTL_STRINGDATA** ppThis
/* Check ASCII range */ /* Check ASCII range */
SAL_WARN_IF( ((unsigned char)*pCharStr) > 127, "rtl.string", SAL_WARN_IF( ((unsigned char)*pCharStr) > 127, "rtl.string",
"rtl_uString_newFromLiteral - Found char > 127" ); "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 = *pCharStr;
pBuffer++; pBuffer++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment