Skip to content

Fix uninitialized value warnings in CDC - #586

Open
earlephilhower wants to merge 1 commit into
adafruit:masterfrom
earlephilhower:fixw
Open

Fix uninitialized value warnings in CDC#586
earlephilhower wants to merge 1 commit into
adafruit:masterfrom
earlephilhower:fixw

Conversation

@earlephilhower

Copy link
Copy Markdown
Contributor

C++ doesn't prefill all values to 0 when only one value is specified in a struct initializer. GCC with -Wall will warn about this if it sees it.

Replace the partial struct initialization with a C++ 0-init {} followed by a manual setting of the CDC RTS/DTR member.

Fixes the -Werror shown below with -Wall

/home/runner/arduino_ide/hardware/pico/rp2040/libraries/Adafruit_TinyUSB_Arduino/src/arduino/../class/cdc/cdc_host.h: In function 'bool tuh_cdc_set_dtr(uint8_t, bool, tuh_xfer_cb_t, uintptr_t)':
/home/runner/arduino_ide/hardware/pico/rp2040/libraries/Adafruit_TinyUSB_Arduino/src/arduino/../class/cdc/cdc_host.h:154:58: error: missing initializer for member 'cdc_line_control_state_t::<unnamed struct>::rts' [-Werror=missing-field-initializers]
  154 |   cdc_line_control_state_t line_state = {.dtr = dtr_state};
      |                                                          ^
/home/runner/arduino_ide/hardware/pico/rp2040/libraries/Adafruit_TinyUSB_Arduino/src/arduino/../class/cdc/cdc_host.h: In function 'bool tuh_cdc_set_rts(uint8_t, bool, tuh_xfer_cb_t, uintptr_t)':
/home/runner/arduino_ide/hardware/pico/rp2040/libraries/Adafruit_TinyUSB_Arduino/src/arduino/../class/cdc/cdc_host.h:162:58: error: missing initializer for member 'cdc_line_control_state_t::<unnamed struct>::dtr' [-Werror=missing-field-initializers]
  162 |   cdc_line_control_state_t line_state = {.rts = rts_state};
      |                                                          ^
cc1plus: all warnings being treated as errors

C++ doesn't prefill all values to 0 when only one value is specified
in a struct initializer.  GCC with -Wall will warn about this if it
sees it.

Replace the partial struct initialization with a C++ 0-init {}
followed by a manual setting of the CDC RTS/DTR member.
@earlephilhower

Copy link
Copy Markdown
Contributor Author

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