esp-mdf icon indicating copy to clipboard operation
esp-mdf copied to clipboard

Suggested parenthesis around expression in mwifi.c

Open mmrein opened this issue 2 years ago • 3 comments

Environment

  • Possibly related to all - bug in mwifi.c source file
  • MDF version: cf502740f5a6c82a0dc3059e7591c262795f70b2 (current master)

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.

mmrein avatar Mar 24 '22 10:03 mmrein

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?

Jiangyafeng avatar Apr 19 '22 13:04 Jiangyafeng

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.

mmrein avatar Apr 20 '22 07:04 mmrein

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

Jiangyafeng avatar Apr 21 '22 03:04 Jiangyafeng