Skip to content

[C++] Incorrect computeEncodedLength() generated for VarData member - uses sizeof(null) instead of sizeof(char) #1093

@spanti

Description

@spanti

Description

When generating the C++ codec for UtxErrorDto (and other messages containing varData fields), the generated method computeEncodedLength() contains incorrect size calculations. Specifically, the generator emits:

encodedLength += m_identity.size() * sizeof(null);

However, null is not a valid type and results in incorrect encoded length calculation. Replacing sizeof(null) with sizeof(char) fixes the issue.

Generated Code (Incorrect)

std::size_t computeEncodedLength() const
{
    std::size_t encodedLength = 0;
    encodedLength += UtxLoginCommand::sbeBlockLength();

    encodedLength += UtxLoginCommand::identityHeaderLength();
    encodedLength += m_identity.size() * sizeof(null);

    encodedLength += UtxLoginCommand::credentialHeaderLength();
    encodedLength += m_credential.size() * sizeof(null);

    encodedLength += UtxLoginCommand::collectedDataHeaderLength();
    encodedLength += m_collectedData.size() * sizeof(null);

    return encodedLength;
}

Corrected Code (Works as expected)

std::size_t computeEncodedLength() const
{
    std::size_t encodedLength = 0;
    encodedLength += UtxLoginCommand::sbeBlockLength();

    encodedLength += UtxLoginCommand::identityHeaderLength();
    encodedLength += m_identity.size() * sizeof(char);

    encodedLength += UtxLoginCommand::credentialHeaderLength();
    encodedLength += m_credential.size() * sizeof(char);

    encodedLength += UtxLoginCommand::collectedDataHeaderLength();
    encodedLength += m_collectedData.size() * sizeof(char);

    return encodedLength;
}

Expected Behavior

The generator should use:

sizeof(char)

for all varData fields, since they are encoded as byte arrays.

Actual Behavior

The generator outputs:

sizeof(null)

which is invalid and results in incorrect encoded length calculation.

Steps to Reproduce

Define a message containing <data type="varData">

Generate C++ codecs

Inspect the generated computeEncodedLength() method

Observe that sizeof(null) is emitted instead of sizeof(char)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions