Skip to content

string padding: incorrect length. #646

Closed
@LeeAlfay

Description

@LeeAlfay

Hi,

The following method is copying a string to a SBE message buffer but the padding is not working for a string length less than 20. The loop that adds the padding (this part: start < length) needs to use the buffer size not the srcLength, no?

SBEOrderResponseMsg &putSymbol(const std::string& str)
{
    const size_t srcLength = str.length();
    if (srcLength > 20)
    {
         throw std::runtime_error("string too large for putSymbol [E106]");
    }

    size_t length = srcLength < 20 ? srcLength : 20;
    std::memcpy(m_buffer + m_offset + 25, str.c_str(), length);
    for (size_t start = srcLength; start < **length**; ++start)
    {
        m_buffer[m_offset + 25 + start] = 0;
    }

    return *this;
}

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