Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions source/TrickHLA/Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ void Attribute::initialize(
case TRICK_LONG:
case TRICK_UNSIGNED_LONG:
case TRICK_LONG_LONG:
case TRICK_UNSIGNED_LONG_LONG: {
case TRICK_UNSIGNED_LONG_LONG:
case TRICK_ENUMERATED: {
Comment on lines 351 to +355
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] TRICK_ENUMERATED is grouped with long/long long here, but in byteswap_buffer_copy it is grouped with TRICK_INTEGER. If the behavior is intended to mirror TRICK_INTEGER, consider grouping consistently (or add a brief comment) to avoid confusion about the expected width/semantics for TRICK_ENUMERATED in different code paths.

Copilot uses AI. Check for mistakes.
if ( ( rti_encoding != ENCODING_BIG_ENDIAN )
&& ( rti_encoding != ENCODING_LITTLE_ENDIAN )
&& ( rti_encoding != ENCODING_LOGICAL_TIME )
Expand Down Expand Up @@ -3361,6 +3362,7 @@ void Attribute::byteswap_buffer_copy( // RETURN: -- None.
}
break;
}
case TRICK_ENUMERATED:
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This treats TRICK_ENUMERATED as a 32-bit int by casting to int. If TRICK_ENUMERATED is not guaranteed to be 32-bit across platforms, this can produce incorrect byte-swapping. Consider either (a) documenting and guarding the assumption with a compile-time check (e.g., a static_assert that TRICK_ENUMERATED maps to a 4-byte encoding), or (b) selecting the swap width based on the attribute's encoded size (2/4/8 bytes) to make this portable.

Suggested change
case TRICK_ENUMERATED:
case TRICK_ENUMERATED: {
// Swap based on the actual size of TRICK_ENUMERATED.
size_t elem_size = num_bytes / length;
if (elem_size == sizeof(short)) {
short const *e_src = static_cast<short const *>(src);
short *e_dest = static_cast<short *>(dest);
for (int k = 0; k < length; ++k) {
e_dest[k] = Utilities::byteswap_short(e_src[k]);
}
} else if (elem_size == sizeof(int)) {
int const *e_src = static_cast<int const *>(src);
int *e_dest = static_cast<int *>(dest);
for (int k = 0; k < length; ++k) {
e_dest[k] = Utilities::byteswap_int(e_src[k]);
}
} else if (elem_size == sizeof(long long)) {
long long const *e_src = static_cast<long long const *>(src);
long long *e_dest = static_cast<long long *>(dest);
for (int k = 0; k < length; ++k) {
e_dest[k] = Utilities::byteswap_long_long(e_src[k]);
}
} else {
// Unknown size, just copy.
memcpy(dest, src, num_bytes);
}
break;
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

@simnaut simnaut Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good comment. Looking at the trick project, here is their assumption about TRICK_ENUMERATED. Not a full list, and while there appears to be some cases where the enum could be something other than int, it seems more often than not TRICK_ENUMERATED is assumed to be exclusively int.

case TRICK_INTEGER: {
int const *i_src = static_cast< int const * >( src );
int *i_dest = static_cast< int * >( dest );
Expand Down Expand Up @@ -3515,7 +3517,8 @@ bool Attribute::is_supported_attribute_type() const // RETURN: -- True if suppor
case TRICK_LONG:
case TRICK_UNSIGNED_LONG:
case TRICK_LONG_LONG:
case TRICK_UNSIGNED_LONG_LONG: {
case TRICK_UNSIGNED_LONG_LONG:
case TRICK_ENUMERATED: {
// We do not support an array of primitive types for the logical
// time encoding, otherwise we support everything else.
if ( ( rti_encoding == ENCODING_LOGICAL_TIME ) && ( ref2->attr->num_index > 0 ) ) {
Expand Down