[Libreoffice-commits] .: 2 commits - i18npool/source sal/inc sal/rtl

Lubos Lunak llunak at kemper.freedesktop.org
Mon Apr 2 08:03:42 PDT 2012


 i18npool/source/isolang/isolang.cxx |   20 ++++++++++----------
 sal/inc/rtl/string.hxx              |    4 +++-
 sal/inc/rtl/ustring.hxx             |    3 +++
 sal/rtl/source/strtmpl.cxx          |    2 ++
 4 files changed, 18 insertions(+), 11 deletions(-)

New commits:
commit 1cdb1ea6a8071f9cd802c30ae78a35332782cb31
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Mon Apr 2 16:56:13 2012 +0200

    don't use string literals with embedded \0's
    
    Followup to 791f27683311e487947b0464a0cb132b19fd0e12.

diff --git a/i18npool/source/isolang/isolang.cxx b/i18npool/source/isolang/isolang.cxx
index 5e40487..35a9250 100644
--- a/i18npool/source/isolang/isolang.cxx
+++ b/i18npool/source/isolang/isolang.cxx
@@ -659,9 +659,9 @@ void MsLangId::convertLanguageToIsoNames( LanguageType nLang,
     do
     {
         if ( pEntry->mnLang == nLang )
-        {
-            rLangStr = rtl::OString( pEntry->maLangStr );
-            rCountry = rtl::OString( pEntry->maCountry );
+        {                          // avoid embedded \0 warning
+            rLangStr = rtl::OString( static_cast< const char* >( pEntry->maLangStr ));
+            rCountry = rtl::OString( static_cast< const char* >( pEntry->maCountry ));
             return;
         }
         ++pEntry;
@@ -675,9 +675,9 @@ void MsLangId::convertLanguageToIsoNames( LanguageType nLang,
     do
     {
         if ( pNoneStdEntry->mnLang == nLang )
-        {
-            rLangStr = rtl::OString( pNoneStdEntry->maLangStr );
-            rCountry = rtl::OString( pNoneStdEntry->maCountry );
+        {                          // avoid embedded \0 warning
+            rLangStr = rtl::OString( static_cast< const char* >( pNoneStdEntry->maLangStr ));
+            rCountry = rtl::OString( static_cast< const char* >( pNoneStdEntry->maCountry ));
             return;
         }
         ++pNoneStdEntry;
@@ -1082,12 +1082,12 @@ LanguageType MsLangId::convertUnxByteStringToLanguage(
         rtl::OString aUpperCountry = aCountry.toAsciiUpperCase();
         const IsoLangGLIBCModifiersEntry* pGLIBCModifiersEntry = aImplIsoLangGLIBCModifiersEntries;
         do
-        {
-            if (( aLowerLang.equals( pGLIBCModifiersEntry->maLangStr ) ) &&
-               ( aAtString.equals( pGLIBCModifiersEntry->maAtString ) ))
+        {                         // avoid embedded \0 warning
+            if (( aLowerLang.equals( static_cast< const char* >( pGLIBCModifiersEntry->maLangStr ))) &&
+               ( aAtString.equals( static_cast< const char* >( pGLIBCModifiersEntry->maAtString ))))
             {
                 if ( aUpperCountry.isEmpty() ||
-                     aUpperCountry.equals( pGLIBCModifiersEntry->maCountry ) )
+                     aUpperCountry.equals( static_cast< const char* >( pGLIBCModifiersEntry->maCountry )))
                {
                     return pGLIBCModifiersEntry->mnLang;
                }
commit 60b596665fff7c110c6b12da192f5712fb145028
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Mon Apr 2 16:52:36 2012 +0200

    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.

diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 8dbb413..a00e186 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 8035bdc..518ef3d 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 2a33907..be86ab3 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++;


More information about the Libreoffice-commits mailing list