Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stringop-overflow warnings with gcc 14.2 #4446

Open
ZedThree opened this issue Jan 24, 2025 · 1 comment
Open

stringop-overflow warnings with gcc 14.2 #4446

ZedThree opened this issue Jan 24, 2025 · 1 comment

Comments

@ZedThree
Copy link

Building current master (925234) with gcc 14.2.1 gives me a bunch of warnings about "reading/writing 128 bytes from a region of size 16":

In file included from /usr/include/c++/14/string:51,
                 from /home/peter/Tools/ADIOS2/source/adios2/core/AttributeBase.h:15,
                 from /home/peter/Tools/ADIOS2/source/adios2/core/Attribute.h:14,
                 from /home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Base.h:11,
                 from /home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.h:11,
                 from /home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp:8:
In static member function ‘static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const char; _Up = char; bool _IsMove = false]’,
    inlined from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:521:30,
    inlined from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:548:42,
    inlined from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = __gnu_cxx::__normal_iterator<char*, vector<char> >]’ at /usr/include/c++/14/bits/stl_algobase.h:555:31,
    inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = const char*; _OI = __gnu_cxx::__normal_iterator<char*, vector<char> >]’ at /usr/include/c++/14/bits/stl_algobase.h:651:7,
    inlined from ‘void adios2::helper::CopyToBuffer(std::vector<char>&, std::size_t&, const T*, std::size_t) [with T = long unsigned int]’ at /home/peter/Tools/ADIOS2/source/adios2/helper/adiosMemory.inl:144:14,
    inlined from ‘static std::vector<char> adios2::format::BP5Helper::BuildNodeContrib(digest, std::size_t, std::vector<adios2::format::BP5Base::MetaMetaInfoBlock>, std::size_t, std::vector<long unsigned int>)’ at /home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp:61:25:
/usr/include/c++/14/bits/stl_algobase.h:452:30: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ reading 128 bytes from a region of size 16 [-Wstringop-overread]
  452 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp: In static member function ‘static std::vector<char> adios2::format::BP5Helper::BuildNodeContrib(digest, std::size_t, std::vector<adios2::format::BP5Base::MetaMetaInfoBlock>, std::size_t, std::vector<long unsigned int>)’:
/home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp:49:42: note: source object ‘attrHash’ of size 16
   49 | BP5Helper::BuildNodeContrib(const digest attrHash, const size_t attrSize,
      |                             ~~~~~~~~~~~~~^~~~~~~~
In static member function ‘static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const char; _Up = char; bool _IsMove = false]’,
    inlined from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:521:30,
    inlined from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:548:42,
    inlined from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = __gnu_cxx::__normal_iterator<char*, vector<char> >]’ at /usr/include/c++/14/bits/stl_algobase.h:555:31,
    inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = const char*; _OI = __gnu_cxx::__normal_iterator<char*, vector<char> >]’ at /usr/include/c++/14/bits/stl_algobase.h:651:7,
    inlined from ‘void adios2::helper::CopyToBuffer(std::vector<char>&, std::size_t&, const T*, std::size_t) [with T = long unsigned int]’ at /home/peter/Tools/ADIOS2/source/adios2/helper/adiosMemory.inl:144:14,
    inlined from ‘static std::vector<char> adios2::format::BP5Helper::BuildNodeContrib(digest, std::size_t, std::vector<adios2::format::BP5Base::MetaMetaInfoBlock>, std::size_t, std::vector<long unsigned int>)’ at /home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp:68:29:
/usr/include/c++/14/bits/stl_algobase.h:452:30: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ reading 128 bytes from a region of size 16 [-Wstringop-overread]
  452 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp: In static member function ‘static std::vector<char> adios2::format::BP5Helper::BuildNodeContrib(digest, std::size_t, std::vector<adios2::format::BP5Base::MetaMetaInfoBlock>, std::size_t, std::vector<long unsigned int>)’:
/home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp:66:16: note: source object ‘D’ of size 16
   66 |         digest D;
      |                ^
In static member function ‘static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const char; _Up = char; bool _IsMove = false]’,
    inlined from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:521:30,
    inlined from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:548:42,
    inlined from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:555:31,
    inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:651:7,
    inlined from ‘void adios2::helper::CopyFromBuffer(const char*, std::size_t&, T*, std::size_t) [with T = long unsigned int]’ at /home/peter/Tools/ADIOS2/source/adios2/helper/adiosMemory.inl:220:14,
    inlined from ‘void adios2::helper::ReadArray(const std::vector<char>&, std::size_t&, T*, std::size_t, bool) [with T = long unsigned int]’ at /home/peter/Tools/ADIOS2/source/adios2/helper/adiosMemory.inl:333:19,
    inlined from ‘static void adios2::format::BP5Helper::BreakdownIncomingMInfo(std::vector<long unsigned int>, std::vector<char>, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<digest>&)’ at /home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp:199:26:
/usr/include/c++/14/bits/stl_algobase.h:452:30: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ writing 128 bytes into a region of size 16 overflows the destination [-Wstringop-overflow=]
  452 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp: In static member function ‘static void adios2::format::BP5Helper::BreakdownIncomingMInfo(std::vector<long unsigned int>, std::vector<char>, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<digest>&)’:
/home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp:195:16: note: destination object ‘thisAttrHash’ of size 16
  195 |         digest thisAttrHash;
      |                ^~~~~~~~~~~~
In static member function ‘static _Up* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(_Tp*, _Tp*, _Up*) [with _Tp = const char; _Up = char; bool _IsMove = false]’,
    inlined from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:521:30,
    inlined from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:548:42,
    inlined from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:555:31,
    inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = const char*; _OI = char*]’ at /usr/include/c++/14/bits/stl_algobase.h:651:7,
    inlined from ‘void adios2::helper::CopyFromBuffer(const char*, std::size_t&, T*, std::size_t) [with T = long unsigned int]’ at /home/peter/Tools/ADIOS2/source/adios2/helper/adiosMemory.inl:220:14,
    inlined from ‘void adios2::helper::ReadArray(const std::vector<char>&, std::size_t&, T*, std::size_t, bool) [with T = long unsigned int]’ at /home/peter/Tools/ADIOS2/source/adios2/helper/adiosMemory.inl:333:19,
    inlined from ‘static void adios2::format::BP5Helper::BreakdownIncomingMInfo(std::vector<long unsigned int>, std::vector<char>, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<digest>&)’ at /home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp:215:30:
/usr/include/c++/14/bits/stl_algobase.h:452:30: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ writing 128 bytes into a region of size 16 overflows the destination [-Wstringop-overflow=]
  452 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp: In static member function ‘static void adios2::format::BP5Helper::BreakdownIncomingMInfo(std::vector<long unsigned int>, std::vector<char>, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<long unsigned int>&, std::vector<digest>&)’:
/home/peter/Tools/ADIOS2/source/adios2/toolkit/format/bp5/BP5Helper.cpp:214:20: note: destination object ‘thisMMB’ of size 16
  214 |             digest thisMMB;
      |                    ^~~~~~~

Offending code is in BP5Helper::BuildNodeContrib:

helper::CopyToBuffer(ret, position, &attrHash.x[0], sizeof(digest));

(and similar)

My completely naive guess is that the last argument to CopyToBuffer is the number of elements, so this should probably be the following instead?

helper::CopyToBuffer(ret, position, &attrHash.x[0], 2);

Configured like:

$ cmake . -B build -DADIOS2_USE_MPI=on -DADIOS2_USE_Fortran=off -DADIOS2_USE_Python=off -DADIOS2_BUILD_EXAMPLES=OFF -DADIOS2_USE_SST=off -GNinja
@eisenhauer
Copy link
Member

Hmm. Thank you, it looks like this is a problem. I was initially curious how it got by the memory sanitizers in CI, but I think they don't run on MPI tests and this code is only active then. Sigh. That's really something we need to look into. @vicentebolea ? Any thoughts there? Until then, I'll do some manual checking before putting in fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants