[Libreoffice-commits] core.git: include/rtl include/sal xmlsecurity/source

Noel Grandin noel.grandin at collabora.co.uk
Fri May 26 08:35:54 UTC 2017


 include/rtl/strbuf.hxx                   |    4 -
 include/rtl/string.hxx                   |    2 
 include/rtl/ustrbuf.hxx                  |    4 -
 include/rtl/ustring.hxx                  |    2 
 include/sal/types.h                      |   16 +++++++
 xmlsecurity/source/xmlsec/biginteger.cxx |   67 ++++++++++++++-----------------
 6 files changed, 53 insertions(+), 42 deletions(-)

New commits:
commit 24b2c636a230c04ab4b9c6ed7d041f6420f959f1
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu May 25 11:47:52 2017 +0200

    create SAL_RETURNS_NONNULL annotation
    
    and apply it to some methods in OString and OUString
    
    Change-Id: I30e91f961b6d310799d3641f68b7ed54b3080f3a
    Reviewed-on: https://gerrit.libreoffice.org/38020
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 791eb142f9dc..eb5d4f738568 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -441,7 +441,7 @@ public:
     /**
         Return a null terminated character array.
      */
-    const sal_Char* getStr() const { return pData->buffer; }
+    const sal_Char* getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
 
     /**
       Access to individual characters.
@@ -709,7 +709,7 @@ public:
 
        @since LibreOffice 4.4
     */
-    char * appendUninitialized(sal_Int32 length) {
+    char * appendUninitialized(sal_Int32 length) SAL_RETURNS_NONNULL {
         sal_Int32 n = getLength();
         rtl_stringbuffer_insert(&pData, &nCapacity, n, NULL, length);
         return pData->buffer + n;
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 37876983cd1b..2753713fc66f 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -432,7 +432,7 @@ public:
       @return a pointer to a null-terminated byte string representing the
       characters of this string object.
     */
-    const sal_Char * getStr() const { return pData->buffer; }
+    const sal_Char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
 
     /**
       Access to individual characters.
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 04ba896b9b48..9dbc2621a7ae 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -474,7 +474,7 @@ public:
     /**
         Return a null terminated unicode character array.
      */
-    const sal_Unicode*  getStr() const { return pData->buffer; }
+    const sal_Unicode*  getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
 
     /**
       Access to individual characters.
@@ -885,7 +885,7 @@ public:
 
        @since LibreOffice 4.4
     */
-    sal_Unicode * appendUninitialized(sal_Int32 length) {
+    sal_Unicode * appendUninitialized(sal_Int32 length) SAL_RETURNS_NONNULL {
         sal_Int32 n = getLength();
         rtl_uStringbuffer_insert(&pData, &nCapacity, n, NULL, length);
         return pData->buffer + n;
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 50f3be69bbbd..8b1cd3a1404f 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -662,7 +662,7 @@ public:
 
       @return   a pointer to the Unicode characters buffer for this object.
     */
-    const sal_Unicode * getStr() const { return pData->buffer; }
+    const sal_Unicode * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
 
     /**
       Access to individual characters.
diff --git a/include/sal/types.h b/include/sal/types.h
index 30939f130281..b6d6730e88a5 100644
--- a/include/sal/types.h
+++ b/include/sal/types.h
@@ -687,6 +687,22 @@ inline char16_t const * SAL_U(wchar_t const * p)
 /// @endcond
 #endif
 
+
+/** Indicate where function/methods that return a pointer always
+    return a non-nullptr value.
+
+    Note that MSVC supports this feature via it's SAL _Ret_notnull_
+    annotation, but since it's in a completely different place on
+    the function declaration, it's a little hard to support both.
+
+    @since LibreOffice 5.5
+*/
+#if (defined __GNUC__ && __GNUC__ > 4) || defined __clang__
+#define SAL_RETURNS_NONNULL  __attribute__((returns_nonnull))
+#else
+#define SAL_RETURNS_NONNULL
+#endif
+
 #endif // INCLUDED_SAL_TYPES_H
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/xmlsec/biginteger.cxx b/xmlsecurity/source/xmlsec/biginteger.cxx
index 4f1004be1a97..3981754cb776 100644
--- a/xmlsecurity/source/xmlsec/biginteger.cxx
+++ b/xmlsecurity/source/xmlsec/biginteger.cxx
@@ -29,53 +29,48 @@ namespace xmlsecurity
 {
 Sequence< sal_Int8 > numericStringToBigInteger ( const OUString& numeral )
 {
-    if( numeral.getStr() != nullptr )
-    {
-        xmlChar* chNumeral ;
-        const xmlSecByte* bnInteger ;
-        xmlSecSize length ;
-        xmlSecBn bn ;
+    xmlChar* chNumeral ;
+    const xmlSecByte* bnInteger ;
+    xmlSecSize length ;
+    xmlSecBn bn ;
 
-        OString onumeral = OUStringToOString( numeral , RTL_TEXTENCODING_ASCII_US ) ;
+    OString onumeral = OUStringToOString( numeral , RTL_TEXTENCODING_ASCII_US ) ;
 
-        chNumeral = xmlStrndup( reinterpret_cast<const xmlChar*>(onumeral.getStr()), ( int )onumeral.getLength() ) ;
-
-        if( xmlSecBnInitialize( &bn, 0 ) < 0 ) {
-            xmlFree( chNumeral ) ;
-            return Sequence< sal_Int8 >();
-        }
-
-        if( xmlSecBnFromDecString( &bn, chNumeral ) < 0 ) {
-            xmlFree( chNumeral ) ;
-            xmlSecBnFinalize( &bn ) ;
-            return Sequence< sal_Int8 >();
-        }
+    chNumeral = xmlStrndup( reinterpret_cast<const xmlChar*>(onumeral.getStr()), ( int )onumeral.getLength() ) ;
 
+    if( xmlSecBnInitialize( &bn, 0 ) < 0 ) {
         xmlFree( chNumeral ) ;
+        return Sequence< sal_Int8 >();
+    }
 
-        length = xmlSecBnGetSize( &bn ) ;
-        if( length <= 0 ) {
-            xmlSecBnFinalize( &bn ) ;
-            return Sequence< sal_Int8 >();
-        }
+    if( xmlSecBnFromDecString( &bn, chNumeral ) < 0 ) {
+        xmlFree( chNumeral ) ;
+        xmlSecBnFinalize( &bn ) ;
+        return Sequence< sal_Int8 >();
+    }
 
-        bnInteger = xmlSecBnGetData( &bn ) ;
-        if( bnInteger == nullptr ) {
-            xmlSecBnFinalize( &bn ) ;
-            return Sequence< sal_Int8 >();
-        }
+    xmlFree( chNumeral ) ;
 
-        Sequence< sal_Int8 > integer( length ) ;
-        for( xmlSecSize i = 0 ; i < length ; i ++ )
-        {
-            integer[i] = *( bnInteger + i ) ;
-        }
+    length = xmlSecBnGetSize( &bn ) ;
+    if( length <= 0 ) {
+        xmlSecBnFinalize( &bn ) ;
+        return Sequence< sal_Int8 >();
+    }
 
+    bnInteger = xmlSecBnGetData( &bn ) ;
+    if( bnInteger == nullptr ) {
         xmlSecBnFinalize( &bn ) ;
-        return integer ;
+        return Sequence< sal_Int8 >();
+    }
+
+    Sequence< sal_Int8 > integer( length ) ;
+    for( xmlSecSize i = 0 ; i < length ; i ++ )
+    {
+        integer[i] = *( bnInteger + i ) ;
     }
 
-    return Sequence< sal_Int8 >();
+    xmlSecBnFinalize( &bn ) ;
+    return integer ;
 }
 
 OUString bigIntegerToNumericString ( const Sequence< sal_Int8 >& integer )


More information about the Libreoffice-commits mailing list