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

Increase integer width for CPF address item count. #463

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

jvalenzuela
Copy link
Contributor

No description provided.

@@ -271,7 +271,7 @@ EipStatus CreateCommonPacketFormatStructure(const EipUint8 *data,
return kEipStatusError;
}

CipUsint address_item_count = common_packet_format_data->item_count - 2;
unsigned int address_item_count = common_packet_format_data->item_count - 2U;

Choose a reason for hiding this comment

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

why do you want to increase the width? the specification states its a USINT

Choose a reason for hiding this comment

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

Oh sorry, you are right. its an UINT.
Could we please use CipUint to create a direct match with the specification?
It helpes me a lot to keep track which variables are part of the interface, and which are just part of the implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Try 417202a.

@jvalenzuela
Copy link
Contributor Author

jvalenzuela commented Jul 25, 2023

The spec I have, Volume 2, 1.4, section 2-6.1 says it item count is a UINT.

Regarding the use of unsigned int instead of CipUint, cpf_data->item count(EipUint16) has a rank equal to or lower than unsigned int on any machine, so it will be implictly promoted to unsigned int. Now the right side of the assignment will yield an unsigned int, which causes a warning due to implicit conversion to a smaller integer with gcc -Wconversion, unsigned int -> CipUsint or CipUint.

Since the address_item_count isn't going to be serialized, I went with a machine-dependent unsigned int as it is guaranteed to handle UINT, and matches the promoted result of cpf_data->item_count - 2U.

Maybe adding a comment conveying the above justification would be merited.

Another idea would be to use CipUint and cast the expression:
CipUint address_item_count = (CipUint)(common_packet_format_data->item_count - 2U);

Resolves warning about possible loss of data due to implicit integer
conversion, e.g., Visual Studio C4244.
@MartinMelikMerkumians MartinMelikMerkumians merged commit 4a4d30b into EIPStackGroup:master Aug 31, 2023
1 check failed
@jvalenzuela jvalenzuela deleted the itemcnt branch September 3, 2023 15:45
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

Successfully merging this pull request may close these issues.

2 participants