Menu

false positive

2024-11-21
2024-11-21
  • Rob Deckers

    Rob Deckers - 2024-11-21

    With cppcheck 2.15.
    In our code we use an std::byte[] buffer, because we need the fixed size, no dynamic memory after creation
    , buffer_{std::make_unique_for_overwrite<std::byte[]>(bufferSize)}</std::byte[]>

    When we want to write to this buffer, we serialize and provide a std::span with buffer.get.
    void write(const Entry& entry)
    {
    const auto size = SerializationType::serialize(entry, std::span{buffer_.get(), bufferSize_});

     The serialize function definition:
    

    std::size_t Serialization::serialize(const Entry& entry, std::span<std::byte> buffer)</std::byte>

    Cppcheck complains:
    component_projects\data_logger\src\trace_logger\buffer\details\LinearEntryBuffer.hpp:51:87: portability: 'buffer_.get()' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]
    const auto size = SerializationType::serialize(entry, std::span{buffer_.get() + writeIndex_, bufferSize_ - writeIndex_});

    I think this is a false positive due to the pointers are byte pointers not void pointers.

     
  • CHR

    CHR - 2024-11-21

    Sounds like https://trac.cppcheck.net/ticket/12748
    Can you try with current head?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.