Skip to content

There are bugs in Buffer.h #305

@chenxm

Description

@chenxm

In library Foundation, Have some bugs in Buffer.h

145 std::memcpy(ptr, _ptr, _used);
should be:
std::memcpy(ptr, _ptr, _used * sizeof(T));

173 if (preserveContent)
174 std::memcpy(ptr, _ptr, _used < newCapacity ? _used : newCapacity);
should be:
if (preserveContent)
{
std::size_t newSz = _used < newCapacity ? _used : newCapacity;
std::memcpy(ptr, _ptr, newSz * sizeof(T));
}

190 std::memcpy(_ptr, buf, sz);
should be:
std::memcpy(_ptr, buf, sz * sizeof(T));

199 std::memcpy(_ptr + _used - sz, buf, sz);
should be:
199 std::memcpy(_ptr + _used - sz, buf, sz * sizeof(T));

244 if (std::memcmp(_ptr, other._ptr, _used) == 0)
should be:
if (std::memcmp(_ptr, other._ptr, _used * sizeof(T)) == 0)

There's all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions