Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix warnings related to fixed cmd array. #19193

Merged

Conversation

ellensp
Copy link
Contributor

@ellensp ellensp commented Aug 30, 2020

Requirements

E_STEPPERS > 1 and ENABLED(FILAMENT_LOAD_UNLOAD_GCODES)
menu capable LCD

Description

The above combination produces a compiler warning
Marlin/src/lcd/menu/menu_filament.cpp:142:33: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
142 | sprintf_P(cmd, PSTR("M600 B0 T%i"), int(MenuItemBase::itemIndex));

The warning is valid. If i > 99 the cmd array would overflow and the nul termination would be lost.

Taking inspiration from e8dcbd8
I have fixed this warning, Size of cmd array is determined mathematically vs a fixed length.

Benefits

Warning is gone.

Configurations

Configs used to generate warning.
configs.zip

Related Issues

e8dcbd8

@thinkyhead thinkyhead merged commit 2a72961 into MarlinFirmware:bugfix-2.0.x Aug 31, 2020
thinkyhead pushed a commit to thinkyhead/Marlin that referenced this pull request Sep 2, 2020
vgadreau pushed a commit to vgadreau/Marlin that referenced this pull request Dec 9, 2020
kageurufu pushed a commit to CR30-Users/Marlin-CR30 that referenced this pull request Apr 30, 2021
@ellensp ellensp deleted the bugfix-2.0.x-Change_Filament branch July 1, 2022 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants