Skip to content

Fix compiler warning on HardwareTimer #2256

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jan 23, 2024
Merged

Fix compiler warning on HardwareTimer #2256

merged 2 commits into from
Jan 23, 2024

Conversation

ldursw
Copy link
Contributor

@ldursw ldursw commented Jan 22, 2024

This PR fixes a compiler warning when compiling with -O3. There's no bounds check in pauseChannel, which causes this warning. Adding the bounds check fixes the warning.

framework-arduinoststm32\libraries\SrcWrapper\src\HardwareTimer.cpp: In member function 'void HardwareTimer::pauseChannel(uint32_t)':
framework-arduinoststm32\libraries\SrcWrapper\src\HardwareTimer.cpp:203:31: warning: array subscript 4 is above array bounds of 'TimerModes_t [4]' [-Warray-bounds]
  203 |   if (_ChannelMode[channel - 1] == TIMER_INPUT_FREQ_DUTY_MEASUREMENT) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~~^
In file included from framework-arduinoststm32\cores\arduino\stm32/analog.h:45,
                 from framework-arduinoststm32\cores\arduino/board.h:8,
                 from framework-arduinoststm32\cores\arduino/wiring.h:40,
                 from framework-arduinoststm32\cores\arduino/Arduino.h:36,
                 from framework-arduinoststm32\libraries\SrcWrapper\src\HardwareTimer.cpp:26:
framework-arduinoststm32\cores\arduino/HardwareTimer.h:188:19: note: while referencing 'HardwareTimer::_ChannelMode'
  188 |     TimerModes_t  _ChannelMode[TIMER_CHANNELS];
      |                   ^~~~~~~~~~~~
framework-arduinoststm32\libraries\SrcWrapper\src\HardwareTimer.cpp:203:31: warning: array subscript 4 is above array bounds of 'TimerModes_t [4]' [-Warray-bounds]
  203 |   if (_ChannelMode[channel - 1] == TIMER_INPUT_FREQ_DUTY_MEASUREMENT) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~~^
framework-arduinoststm32\cores\arduino/HardwareTimer.h:188:19: note: while referencing 'HardwareTimer::_ChannelMode'
  188 |     TimerModes_t  _ChannelMode[TIMER_CHANNELS];
      |                   ^~~~~~~~~~~~

Signed-off-by: ldursw <37294448+ldursw@users.noreply.github.com>
@fpistm fpistm added the fix 🩹 Bug fix label Jan 23, 2024
@fpistm fpistm added this to the 2.8.0 milestone Jan 23, 2024
@fpistm fpistm self-requested a review January 23, 2024 09:03
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm
Copy link
Member

fpistm commented Jan 23, 2024

Hi @ldursw
thanks for the PR.

@fpistm fpistm merged commit de1e1c5 into stm32duino:main Jan 23, 2024
@ldursw ldursw deleted the patch-1 branch January 23, 2024 15:49
tadtruex pushed a commit to TadAtThayer/Arduino_Core_STM32 that referenced this pull request Apr 23, 2024
Signed-off-by: ldursw <37294448+ldursw@users.noreply.github.com>
Co-authored-by: Frederic Pillon <frederic.pillon@st.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
fix 🩹 Bug fix
Projects
Development

Successfully merging this pull request may close these issues.

2 participants