Skip to content

C++ stub getters/setters for non-char arrays ignore element size #402

Closed

Description

@da4089

For a type defined like

  <types>
    <type name="int3" primitiveType="int32" semanticType="FooType" length="3"/>
  </types>

and used in a message like

    <field name="array" id="2" type="int3"/>

the generated stubs contain getters and setters like

    std::uint64_t getArray(char *dst, const std::uint64_t length) const
    {
        if (length > 3)
        {
             throw std::runtime_error("length too large for getArray [E106]");
        }

        std::memcpy(dst, m_buffer + m_offset + 0, length);
        return length;
    }

    Simple3 &putArray(const char *src)
    {
        std::memcpy(m_buffer + m_offset + 0, src, 3);
        return *this;
    }

In both cases, the call to memcpy uses a size of 3 (bytes), but it should be 12 (3 elements, each of 4 bytes for int32)?

Activity

  1. mjpt777 commented on Jun 6, 2017

    @mjpt777
    Contributor

    I've fixed this. However the use of these methods should only be used when it is known the machine is the correct endianness for the schema as no conversation is applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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