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_});
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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_});
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.
Sounds like https://trac.cppcheck.net/ticket/12748
Can you try with current head?