Skip to content

Commit 7eb8767

Browse files
committed
[cpp] Copy elements of the correct size in generated array accessors for cpp codec. Issue aeron-io#402.
1 parent f34afdc commit 7eb8767

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,23 +1108,25 @@ private CharSequence generateArrayProperty(
11081108
indent + " throw std::runtime_error(\"length too large for get%1$s [E106]\");\n" +
11091109
indent + " }\n\n" +
11101110
"%3$s" +
1111-
indent + " std::memcpy(dst, m_buffer + m_offset + %4$d, length);\n" +
1111+
indent + " std::memcpy(dst, m_buffer + m_offset + %4$d, sizeof(%5$s) * length);\n" +
11121112
indent + " return length;\n" +
11131113
indent + " }\n\n",
11141114
toUpperFirstChar(propertyName),
11151115
token.arrayLength(),
11161116
generateArrayFieldNotPresentCondition(token.version(), indent),
1117-
offset));
1117+
offset,
1118+
cppTypeName));
11181119

11191120
sb.append(String.format(
11201121
indent + " %1$s &put%2$s(const char *src)\n" +
11211122
indent + " {\n" +
1122-
indent + " std::memcpy(m_buffer + m_offset + %3$d, src, %4$d);\n" +
1123+
indent + " std::memcpy(m_buffer + m_offset + %3$d, src, sizeof(%4$s) * %5$d);\n" +
11231124
indent + " return *this;\n" +
11241125
indent + " }\n\n",
11251126
containingClassName,
11261127
toUpperFirstChar(propertyName),
11271128
offset,
1129+
cppTypeName,
11281130
token.arrayLength()));
11291131

11301132
if (token.encoding().primitiveType() == PrimitiveType.CHAR)

0 commit comments

Comments
 (0)