diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-05-25 11:47:52 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-05-26 10:35:30 +0200 |
commit | 24b2c636a230c04ab4b9c6ed7d041f6420f959f1 (patch) | |
tree | 400edf162c26e51817c2ade75bbd259ae320d99f /include | |
parent | 59793d67d4c0324730e30d71d94ba5173643d79c (diff) |
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@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r-- | include/rtl/strbuf.hxx | 4 | ||||
-rw-r--r-- | include/rtl/string.hxx | 2 | ||||
-rw-r--r-- | include/rtl/ustrbuf.hxx | 4 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 2 | ||||
-rw-r--r-- | include/sal/types.h | 16 |
5 files changed, 22 insertions, 6 deletions
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: */ |