Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
da4089 opened this issue Oct 26, 2016 · 1 comment
Closed

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

da4089 opened this issue Oct 26, 2016 · 1 comment

Comments

@da4089
Copy link

da4089 commented Oct 26, 2016

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)?

mjpt777 added a commit that referenced this issue Jun 6, 2017
@mjpt777
Copy link
Contributor

mjpt777 commented Jun 6, 2017

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.

@mjpt777 mjpt777 closed this as completed Jun 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants