espressif / esp-mdf

Espressif Mesh Development Framework, limited maintain, recommend to use https://github.com/espressif/esp-mesh-lite
Other
774 stars 253 forks source link

Suggested parenthesis around expression in mwifi.c #281

Open mmrein opened 2 years ago

mmrein commented 2 years ago

Environment

Problem Description

Missing parenthesis around expression: https://github.com/espressif/esp-mdf/blob/cf502740f5a6c82a0dc3059e7591c262795f70b2/components/mwifi/mwifi.c#L704

I did not really experience any issue while running my app that should be related, but above expression without parenthesis does not seem right.

Expected Behavior

Build without warning, explicit use of parenthesis.

Actual Behavior

Builds with warning, possible unexpected behaviour.

Jiangyafeng commented 2 years ago

Hi @mmrein There is nothing wrong with this, you can look at the link: https://github.com/espressif/esp-mdf/blob/master/components/mcommon/include/mdf_err.h#L115, the print here, ‘err’ print is the reason for the error.

Did you compile any warning? Could you please provide what kind of warning it is?

mmrein commented 2 years ago

Hi @Jiangyafeng, I see nothing wrong with MDF_ERROR_CHECK macro statement.

Warning literally says (in Eclipse):

Suggested parenthesis around expression 'MDF_ERROR_CHECK(ret != ESP_OK && !(flag & MESH_DATA_GROUP && ret == ESP_ERR_MESH_DISCARD), ret,
                        "Node failed to send packets, dest_addr: " MACSTR
                        ", flag: 0x%02x, opt->type: 0x%02x, opt->len: %d, data->tos: %d, data: %p, size: %d",
                        MAC2STR(dest_addr->addr), flag, opt->type, opt->len, mesh_data.tos, mesh_data.data, mesh_data.size)'
mwifi.c      /components/mwifi  line 704    Code Analysis Problem

because are obviously missing brackets in logical expression (a con in macro statement).

I can change the condition adding the brackets like this for example: ((ret != ESP_OK) && !((flag & MESH_DATA_GROUP) && (ret == ESP_ERR_MESH_DISCARD)). Warning is resolved, but I'm pretty sure the evaluation will be different than original.

If nothing else, it is unclear how the logical expression should be evaluated.

Jiangyafeng commented 2 years ago

Well, thank you very much for the offer. You made the code clearer. This will be updated later.