Skip to content

Reduce build warnings ( [-Wmissing-field-initializers] ) #1699

@henrygab

Description

@henrygab

Version/revision of the library used

v2.8.0

Describe the bug

Build warnings caused by initialization of a structure without the requisite fields in ir_Kelon.cpp line 443.

To Reproduce

Use the library. Enable all warnings in GCC via -Wall -Wextra.

Actual results

Collapsed simplified build warnings

...\IRremoteESP8266\src\ir_Kelon.cpp: In member function
'stdAc::state_t IRKelonAc::toCommon(const stdAc::state_t*) const':

...\IRremoteESP8266\src\ir_Kelon.cpp:443:25: 
stdAc::state_t result{};
                      ^

warning: missing initializer for member 'stdAc::state_t::protocol'
warning: missing initializer for member 'stdAc::state_t::model'
warning: missing initializer for member 'stdAc::state_t::power'
warning: missing initializer for member 'stdAc::state_t::mode'
warning: missing initializer for member 'stdAc::state_t::degrees'
warning: missing initializer for member 'stdAc::state_t::celsius'
warning: missing initializer for member 'stdAc::state_t::fanspeed'
warning: missing initializer for member 'stdAc::state_t::swingv'
warning: missing initializer for member 'stdAc::state_t::swingh'
warning: missing initializer for member 'stdAc::state_t::quiet'
warning: missing initializer for member 'stdAc::state_t::turbo'
warning: missing initializer for member 'stdAc::state_t::econo'
warning: missing initializer for member 'stdAc::state_t::light'
warning: missing initializer for member 'stdAc::state_t::filter'
warning: missing initializer for member 'stdAc::state_t::clean'
warning: missing initializer for member 'stdAc::state_t::beep'
warning: missing initializer for member 'stdAc::state_t::sleep'
warning: missing initializer for member 'stdAc::state_t::clock'

Example code used

Any code using v2.8.0 of this library, when set to compile with all warnings, should expose this bug.

Expected behaviour

Libraries should build cleanly at all warning levels.

Output of raw data from [IRrecvDumpV2.ino]

N/A

What brand/model IR demodulator are you using?

N/A

Circuit diagram and hardware used (if applicable)

N/A

I have followed the steps in the Troubleshooting Guide & read the FAQ

Yes ... not applicable to this type of bug

Has this library/code previously worked as expected for you?

N/A ... first work to integrate this.

Other useful information

Proposed fix:
Just use the default constructor for stdAc::state_t:

stdAc::state_t result{};

Becomes:

stdAc::state_t result;

This appears to have the correct results. The default constructor appears to zero-initialize all fields in the structure. Each of the embedded enum types, when set to zero, appears to have a reasonable value. And, the result is substantially identical to the expressed intent of the writer of this code.

I'll prep a PR for this....

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions