test: tighten V2TransportTester::SendMessage bounds for GCC 15.2 #33963

pull l0rinc wants to merge 1 commits into bitcoin:master from l0rinc:l0rinc/SendMessage-gcc15 changing 1 files +8 −5
  1. l0rinc commented at 6:49 pm on November 27, 2025: contributor

    Summary

    #33840 adjusted V2TransportTester::SendMessage to avoid a -Warray-bounds false positive with GCC 13, but GCC 15.2 still warns.

    Fix

    Implemented the suggestion in #33840#pullrequestreview-3447477940:

    • take mtype as std::string_view;
    • assert mtype.size() <= CMessageHeader::MESSAGE_TYPE_SIZE;
    • build [0x00][12-byte type][payload] via std::ranges::copy.

    Reproducer

    Before this change, using GCC 15.2 on a Mac

    rm -rfd build && cmake -B build -DENABLE_IPC=OFF -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ && cmake –build build -j$(nproc)

    produces:

     0[100%] Building CXX object src/test/CMakeFiles/test_bitcoin.dir/__/wallet/test/walletload_tests.cpp.o
     1In file included from /opt/homebrew/Cellar/gcc/15.2.0/include/c++/15/array:45,
     2                 from /opt/homebrew/Cellar/gcc/15.2.0/include/c++/15/span:46,
     3                 from /Users/lorinc/bitcoin/src/span.h:10,
     4                 from /Users/lorinc/bitcoin/src/uint256.h:10,
     5                 from /Users/lorinc/bitcoin/src/consensus/params.h:10,
     6                 from /Users/lorinc/bitcoin/src/kernel/chainparams.h:9,
     7                 from /Users/lorinc/bitcoin/src/chainparams.h:9,
     8                 from /Users/lorinc/bitcoin/src/test/net_tests.cpp:5:
     9In function 'constexpr _OutIter std::__copy_move_a2(_InIter, _Sent, _OutIter) [with bool _IsMove = false; _InIter = char*; _Sent = char*; _OutIter = unsigned char*]',
    10    inlined from 'constexpr _OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = char*; _OI = unsigned char*]' at /opt/homebrew/Cellar/gcc/15.2.0/include/c++/15/bits/stl_algobase.h:492:42,
    11    inlined from 'constexpr _OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<char*, __cxx11::basic_string<char> >; _OI = __gnu_cxx::__normal_iterator<unsigned char*, vector<unsigned char> >]' at /opt/homebrew/Cellar/gcc/15.2.0/include/c++/15/bits/stl_algobase.h:500:31,
    12    inlined from 'constexpr _OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<char*, __cxx11::basic_string<char> >; _OI = __gnu_cxx::__normal_iterator<unsigned char*, vector<unsigned char> >]' at /opt/homebrew/Cellar/gcc/15.2.0/include/c++/15/bits/stl_algobase.h:642:7,
    13    inlined from 'void net_tests::{anonymous}::V2TransportTester::SendMessage(std::string, std::span<const unsigned char>)' at /Users/lorinc/bitcoin/src/test/net_tests.cpp:1304:18:
    14/opt/homebrew/Cellar/gcc/15.2.0/include/c++/15/bits/stl_algobase.h:426:32: warning: 'void* __builtin_memmove(void*, const void*, long unsigned int)' offset [0, 1] is out of the bounds [0, 0] [-Warray-bounds=]
    15  426 |               __builtin_memmove(_GLIBCXX_TO_ADDR(__result),
    16      |               ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    17  427 |                                 _GLIBCXX_TO_ADDR(__first),
    18      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~
    19  428 |                                 __n * sizeof(*__first));
    20      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
    21[100%] Linking CXX executable ../../bin/test_bitcoin
    
  2. test: tighten `V2TransportTester::SendMessage` bounds for GCC 15.2
    #33840 adjusted V2TransportTester::SendMessage to avoid a -Warray-bounds false positive with GCC 13, but GCC 15.2 still warns because the helper does not state that the message type must fit into MESSAGE_TYPE_SIZE.
    
    Make that contract explicit and simplify the copy:
    - take mtype as std::string_view;
    - assert mtype.size() <= CMessageHeader::MESSAGE_TYPE_SIZE;
    - build `[0x00][12-byte type][payload]` via std::ranges::copy.
    
    Behavior is unchanged; the remaining GCC warning goes away.
    b3e2ae7aae
  3. DrahtBot added the label Tests on Nov 27, 2025
  4. DrahtBot commented at 6:49 pm on November 27, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33963.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  5. maflcko commented at 8:24 pm on November 27, 2025: member

    I don’t understand this change:

    No objection, but it is clear the compiler is at fault here, and fixing one warning and leaving the others around doesn’t seem that useful.

  6. l0rinc closed this on Nov 27, 2025

  7. l0rinc commented at 8:31 pm on November 27, 2025: contributor
    Thanks for checking, it seems we have to be systematic about this.
  8. l0rinc deleted the branch on Nov 27, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-12-01 21:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me