-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fixed parsing hex numbers in chip config files #1169
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
Conversation
@gszy: Please check for build failures, e.g.:
You may also collect several issues in one PR for your convenience in the future - it shall be fine as well. |
process_chipfile() used to improperly parse hex numbers in chip config files (*.chip), because it used atoi(), which read all such numbers as 0. This resulted, among other issues, in chip_id being set to 0 for all read chips. Such chip id could not match any actual MCU. Replace the atoi() calls with sscanf(…, "%i", …), where %i should match integers in base 10, 8 and 16, depending on the number prefix.
Sorry for the failures—now it should build cleanly, though I’m not sure if that’s a solution you approve: // may set invalid flash types (not defined in enum stlink_flash_type)
if (sscanf(value, "%i", (int *) &ts->flash_type) < 1) |
@gszy This is a good solution to the problem! |
Add a STLINK_FLASH_TYPE_MAX constant that can be used to check if a flash type (an integer) is in the range of valid enum stlink_flash_type values.
I’m trying to make my PRs small and easy to review 🙂
I have added this check in separate commits (feel free to cherry pick what you find useful). There should be some range checks for other parameters as well, but I hope for another PR when I (or someone else) will find more time. |
@gszy Thank you! |
process_chipfile()
used to improperly parse hex numbers in chip config files (*.chip
), because it usedatoi()
, which read all such numbers as 0. This resulted, among other issues, inchip_id
being set to 0 for all read chips. Such chip id could not match any actual MCU.Replace the
atoi()
calls withsscanf(…, "%i", …)
, where%i
should match integers in base 10, 8 and 16, depending on the number prefix.I can rebase this PR once (if) #1166 is merged.