EIPStackGroup / OpENer

OpENer is an EtherNet/IP stack for I/O adapter devices. It supports multiple I/O and explicit connections and includes objects and services for making EtherNet/IP-compliant products as defined in the ODVA specification.
Other
666 stars 257 forks source link

OpENer/source/src/enet_encap /cpf.c line:247 #487

Closed superPN closed 8 months ago

superPN commented 9 months ago

Looks like a bug here: We get item_count from the obtained data Next we judge the value of item_count, If the value of item_count is 2 The program if(common_packet_format_data->item_count >= 1U) { ... }will be executed first Then the program if(common_packet_format_data->item_count >= 2) { ... } will be executed When executing the if(common_packet_format_data->item_count >= 1U) program, the pointer "data" will be moved When executing the if(common_packet_format_data->item_count >= 2) program again, the position of the "data" pointer may not be the position we want.

I feel like it should be written like this: if(common_packet_format_data->item_count >= 2) { ... } else if(common_packet_format_data->item_count >= 1U) { ... }

azoitl commented 9 months ago

If we would write it like you suggested it the code in item_count >=2 would need to duplicate all the code in item >=1.

The idea in the code is to parse as many elements as there are. So the first item first and if there is a second item then the second one.

superPN commented 9 months ago

I understand what you mean. I misunderstood. Thank you for your answer.

azoitl commented 9 months ago

It has been a long time since we wrote that code. By now I would write it a bit different with more methods than our intention would also be clearer.