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

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 29 19:31:59 UTC 2020


 include/rtl/strbuf.hxx  |    8 ++++++++
 include/rtl/string.hxx  |   16 ++++++++++++++++
 include/rtl/ustring.hxx |   16 ++++++++++++++++
 3 files changed, 40 insertions(+)

New commits:
commit e287fde52fb9de5bdf1d00c8a3fbfcca7db9892c
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Sun Dec 15 09:23:14 2019 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Apr 29 21:31:27 2020 +0200

    Silence bogus -Wstringop-overflow with GCC trunk towards GCC 10
    
    ...see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92893> "Unhelpful
    -Wstringop-overflow warning"
    
    Change-Id: I14b2e5e19b57df6f57a9252f27ee4b3feb8ba18c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85161
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx
index 2a303ce998e6..e9a548297016 100644
--- a/include/rtl/strbuf.hxx
+++ b/include/rtl/strbuf.hxx
@@ -569,7 +569,15 @@ public:
             return *this;
         l += pData->length;
         rtl_stringbuffer_ensureCapacity( &pData, &nCapacity, l );
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+        // Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+        // <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92893> "Unhelpful -Wstringop-overflow
+        // warning"):
+        struct Hack { char c; char a[]; };
+        char* end = c.addData( &reinterpret_cast<Hack *>(pData->buffer)->c + pData->length );
+#else
         char* end = c.addData( pData->buffer + pData->length );
+#endif
         *end = '\0';
         pData->length = l;
         return *this;
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 809b0a11bcd5..4f600affdabe 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -273,7 +273,15 @@ public:
         pData = rtl_string_alloc( l );
         if (l != 0)
         {
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+            // Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+            // <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92893> "Unhelpful -Wstringop-overflow
+            // warning"):
+            struct Hack { char c; char a[]; };
+            char* end = c.addData( &reinterpret_cast<Hack *>(pData->buffer)->c );
+#else
             char* end = c.addData( pData->buffer );
+#endif
             pData->length = l;
             *end = '\0';
         }
@@ -381,7 +389,15 @@ public:
             return *this;
         l += pData->length;
         rtl_string_ensureCapacity( &pData, l );
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+        // Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+        // <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92893> "Unhelpful -Wstringop-overflow
+        // warning"):
+        struct Hack { char c; char a[]; };
+        char* end = c.addData( &reinterpret_cast<Hack *>(pData->buffer)->c + pData->length );
+#else
         char* end = c.addData( pData->buffer + pData->length );
+#endif
         *end = '\0';
         pData->length = l;
         return *this;
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 5f0c1032c603..ffe42d139215 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -401,7 +401,15 @@ public:
         pData = rtl_uString_alloc( l );
         if (l != 0)
         {
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+            // Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+            // <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92893> "Unhelpful -Wstringop-overflow
+            // warning"):
+            struct Hack { sal_Unicode c; sal_Unicode a[]; };
+            sal_Unicode* end = c.addData( reinterpret_cast<Hack *>(pData->buffer - 1)->a );
+#else
             sal_Unicode* end = c.addData( pData->buffer );
+#endif
             pData->length = l;
             *end = '\0';
             // TODO realloc in case pData->length is noticeably smaller than l?
@@ -630,7 +638,15 @@ public:
             return *this;
         l += pData->length;
         rtl_uString_ensureCapacity( &pData, l );
+#if defined __GNUC__ && __GNUC__ == 10 && !defined __clang__
+        // Avoid some bogus GCC 10 trunk -Werror=stringop-overflow (see
+        // <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92893> "Unhelpful -Wstringop-overflow
+        // warning"):
+        struct Hack { sal_Unicode c; sal_Unicode a[]; };
+        sal_Unicode* end = c.addData( reinterpret_cast<Hack *>(pData->buffer - 1)->a + pData->length );
+#else
         sal_Unicode* end = c.addData( pData->buffer + pData->length );
+#endif
         *end = '\0';
         pData->length = l;
         return *this;


More information about the Libreoffice-commits mailing list