[Bug tree-optimization/92893] [10 Regression] Unhelpful -Wstringop-overflow warning for a trailing one-element array

sbergman at redhat dot com gcc-bugzilla@gcc.gnu.org
Fri May 1 18:55:29 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92893

--- Comment #9 from Stephan Bergmann <sbergman at redhat dot com> ---
(In reply to Martin Sebor from comment #2)
> Defining Str like so works for the test case:
> 
> struct Str {
>   template<typename T1, typename T2> Str(Cat<T1, T2> c)
>   {
>     struct Flex { char c, a[]; } *p = (Flex*)get();
>     c.add(p->a);
>   }
> };

So I had created <https://gerrit.libreoffice.org/c/core/+/85161> "Silence bogus
-Wstringop-overflow with GCC trunk towards GCC 10" back in last December, and
it sufficed to suppress all those warnings when compiling LibreOffice with
then-trunk GCC, with optimizations enabled.  However, meanwhile GCC has changed
again so that at least one place in the LibreOffice code now produces two
-Werror=stringop-overflow= in one such

  struct Hack { char c; char a[]; };

workaround.  (While in general the workarounds appear to still be effective in
suppressing other such warnings.)  Bisecting, I found that first

> commit ef29b12cfbb4979a89b3cbadbf485a77c8fd8fce
> Author: Martin Sebor <msebor@redhat.com>
> Date:   Sat Dec 14 00:52:46 2019 +0000
> 
>     PR middle-end/91582 - missing heap overflow detection for strcpy

caused a new "writing 1 byte into a region of size 0" at

> In file included from /home/user/libreoffice/include/rtl/string.hxx:41,
>                  from /home/user/libreoffice/include/rtl/ustring.hxx:37,
>                  from /home/user/libreoffice/include/unotest/filters-test.hxx:14,
>                  from /home/user/libreoffice/unotest/source/cpp/filters-test.cxx:14:
> In member function ‘char* rtl::OStringConcat<T1, T2>::addData(char*) const [with T1 = rtl::OStringLiteral; T2 = const char [2]]’,
>     inlined from ‘char* rtl::OStringConcat<T1, T2>::addData(char*) const [with T1 = rtl::OStringConcat<rtl::OStringLiteral, const char [2]>; T2 = rtl::OString]’ at /home/user/libreoffice/include/rtl/stringconcat.hxx:256:114,
>     inlined from ‘rtl::OString::OString(rtl::OStringConcat<T1, T2>&&) [with T1 = rtl::OStringConcat<rtl::OStringLiteral, const char [2]>; T2 = rtl::OString]’ at /home/user/libreoffice/include/rtl/string.hxx:281:34,
>     inlined from ‘void test::FiltersTest::recursiveScan(test::filterStatus, const rtl::OUString&, const rtl::OUString&, const rtl::OUString&, SfxFilterFlags, SotClipboardFormatId, unsigned int, bool)’ at /home/user/libreoffice/unotest/source/cpp/filters-test.cxx:111:67:
> /home/user/libreoffice/include/rtl/stringconcat.hxx:77:11: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
>    77 |     memcpy( buffer, data, length );
>       |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
> In file included from /home/user/libreoffice/include/rtl/ustring.hxx:37,
>                  from /home/user/libreoffice/include/unotest/filters-test.hxx:14,
>                  from /home/user/libreoffice/unotest/source/cpp/filters-test.cxx:14:
> /home/user/libreoffice/include/rtl/string.hxx: In member function ‘void test::FiltersTest::recursiveScan(test::filterStatus, const rtl::OUString&, const rtl::OUString&, const rtl::OUString&, SfxFilterFlags, SotClipboardFormatId, unsigned int, bool)’:
> /home/user/libreoffice/include/rtl/string.hxx:280:32: note: at offset 0 to object ‘rtl::OString::OString(rtl::OStringConcat<T1, T2>&&) [with T1 = rtl::OStringConcat<rtl::OStringLiteral, const char [2]>; T2 = rtl::OString]::Hack::c’ with size 1 declared here
>   280 |             struct Hack { char c; char a[]; };
>       |                                ^

and later

> commit a9a437ffc4269650e34af92c4fb095b7ed98f94a
> Author: Jakub Jelinek <jakub@redhat.com>
> Date:   Tue Mar 17 13:36:41 2020 +0100
> 
>     tree-ssa-strlen: Fix up count_nonzero_bytes* [PR94015]

started to even cause an additional "writing 4 bytes into a region of size 1"

> In file included from /home/user/libreoffice/include/rtl/string.hxx:41,
>                  from /home/user/libreoffice/include/rtl/ustring.hxx:37,
>                  from /home/user/libreoffice/include/unotest/filters-test.hxx:14,
>                  from /home/user/libreoffice/unotest/source/cpp/filters-test.cxx:14:
> In function ‘char* rtl::addDataHelper(char*, const char*, std::size_t)’,
>     inlined from ‘static char* rtl::ToStringHelper<rtl::OStringLiteral>::addData(char*, const rtl::OStringLiteral&)’ at /home/user/libreoffice/include/rtl/string.hxx:1907:91,
>     inlined from ‘char* rtl::OStringConcat<T1, T2>::addData(char*) const [with T1 = rtl::OStringLiteral; T2 = const char [2]]’ at /home/user/libreoffice/include/rtl/stringconcat.hxx:222:103,
>     inlined from ‘char* rtl::OStringConcat<T1, T2>::addData(char*) const [with T1 = rtl::OStringConcat<rtl::OStringLiteral, const char [2]>; T2 = rtl::OString]’ at /home/user/libreoffice/include/rtl/stringconcat.hxx:256:114,
>     inlined from ‘rtl::OString::OString(rtl::OStringConcat<T1, T2>&&) [with T1 = rtl::OStringConcat<rtl::OStringLiteral, const char [2]>; T2 = rtl::OString]’ at /home/user/libreoffice/include/rtl/string.hxx:281:34,
>     inlined from ‘void test::FiltersTest::recursiveScan(test::filterStatus, const rtl::OUString&, const rtl::OUString&, const rtl::OUString&, SfxFilterFlags, SotClipboardFormatId, unsigned int, bool)’ at /home/user/libreoffice/unotest/source/cpp/filters-test.cxx:111:67:
> /home/user/libreoffice/include/rtl/stringconcat.hxx:77:11: error: writing 4 bytes into a region of size 1 [-Werror=stringop-overflow=]
>    77 |     memcpy( buffer, data, length );
>       |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
> In file included from /home/user/libreoffice/include/rtl/ustring.hxx:37,
>                  from /home/user/libreoffice/include/unotest/filters-test.hxx:14,
>                  from /home/user/libreoffice/unotest/source/cpp/filters-test.cxx:14:
> /home/user/libreoffice/include/rtl/string.hxx: In member function ‘void test::FiltersTest::recursiveScan(test::filterStatus, const rtl::OUString&, const rtl::OUString&, const rtl::OUString&, SfxFilterFlags, SotClipboardFormatId, unsigned int, bool)’:
> /home/user/libreoffice/include/rtl/string.hxx:280:32: note: at offset 0 to object ‘rtl::OString::OString(rtl::OStringConcat<T1, T2>&&) [with T1 = rtl::OStringConcat<rtl::OStringLiteral, const char [2]>; T2 = rtl::OString]::Hack::c’ with size 1 declared here
>   280 |             struct Hack { char c; char a[]; };
>       |                                ^

preceding the other warning.


More information about the Gcc-bugs mailing list