build warning: fortify memcpy #23638

issue jsarenik openend this issue on November 30, 2021
  1. jsarenik commented at 9:35 pm on November 30, 2021: none

    This is just a warning, but want to make a note here.

     0  CXX      libbitcoin_server_a-signet.o
     1In file included from /usr/include/c++/10.3.1/cstring:42,
     2                 from ./uint256.h:10,
     3                 from ./consensus/params.h:9,
     4                 from ./signet.h:8,
     5                 from signet.cpp:5:
     6In function 'void* memcpy(void*, const void*, size_t)',
     7    inlined from 'void CVectorWriter::write(const char*, size_t)' at ./streams.h:102:19,
     8    inlined from 'void base_blob<BITS>::Serialize(Stream&) const [with Stream = CVectorWriter; unsigned int BITS = 256]' at ./uint256.h:99:16,
     9    inlined from 'static std::optional<SignetTxs> SignetTxs::Create(const CBlock&, const CScript&)' at ./serialize.h:670:16:
    10/usr/include/fortify/string.h:53:25: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' writing between 1 and 32 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
    11   53 |  return __builtin_memcpy(__od, __os, __n);
    12      |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
    

    Expected behavior

    Clean happy compilation, something like this which comes from later output:

    0...
    1  CXX      wallet/libbitcoin_wallet_a-db.o
    2  CXX      wallet/libbitcoin_wallet_a-dump.o
    3  CXX      wallet/libbitcoin_wallet_a-external_signer_scriptpubkeyman.o
    4  CXX      wallet/libbitcoin_wallet_a-feebumper.o
    5  CXX      wallet/libbitcoin_wallet_a-fees.o
    6  CXX      wallet/libbitcoin_wallet_a-interfaces.o
    7...
    

    Actual behavior

    Warnings during make.

    To reproduce

     0# On Alpine Linux (musl-libc)
     1export CFLAGS="-pipe -s -march=native -mtune=native -O3"
     2export LDFLAGS="-s -no-pie"
     3
     4test -x ./configure || ./autogen.sh
     5./configure \
     6  --without-gui \
     7  --with-incompatible-bdb \
     8  --disable-tests \
     9  --disable-bench \
    10  --disable-zmq \
    11  --disable-hardening \
    12  CFLAGS="$CFLAGS" \
    13  CXXFLAGS="$CFLAGS" \
    14  LDFLAGS="$LDFLAGS"
    15make prefix=$HOME/bitcoin-latest install
    

    System information

    Alpine Linux (musl-libc x86_64)

    0$ uname -mr
    15.10.61-0-lts x86_64
    

    Self-compiled Bitcoin Core exactly from jsarenik/bitcoin@878d8e1c0

    This warning was experienced while compiling version of bitcoin to test #23531 while also rebasing #22563 on top of it and also Alpine Linux locales patch.

    All the rebasing was trivial and maybe the warning is showing for longer but now I noticed it for the first time.

  2. jsarenik added the label Bug on Nov 30, 2021
  3. MarcoFalke commented at 12:53 pm on December 13, 2021: member
    Looks like a compiler bug
  4. MarcoFalke added the label Upstream on Dec 13, 2021
  5. MarcoFalke commented at 12:54 pm on December 13, 2021: member

    For reference, the function is:

     0    void write(const char* pch, size_t nSize)
     1    {
     2        assert(nPos <= vchData.size());
     3        size_t nOverwrite = std::min(nSize, vchData.size() - nPos);
     4        if (nOverwrite) {
     5            memcpy(vchData.data() + nPos, reinterpret_cast<const unsigned char*>(pch), nOverwrite);
     6        }
     7        if (nOverwrite < nSize) {
     8            vchData.insert(vchData.end(), reinterpret_cast<const unsigned char*>(pch) + nOverwrite, reinterpret_cast<const unsigned char*>(pch) + nSize);
     9        }
    10        nPos += nSize;
    11    }
    
  6. fanquake commented at 1:42 pm on December 13, 2021: member

    Looks like a compiler bug

    Yes I think so. Reproduced with GCC 10.3.1 (on Alpine), with -O3, no warning with -O2. Possibly https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94335 or related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92955.

    Not much we can do here, other than suggest you up/downgrade to a non-buggy compiler.

    Going to close for now.

  7. fanquake closed this on Dec 13, 2021

  8. DrahtBot locked this on Dec 13, 2022

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: 2024-12-21 15:12 UTC

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