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 signedness issue with snprintf #27027

Merged
merged 1 commit into from
May 22, 2024

Conversation

durka
Copy link

@durka durka commented May 9, 2024

AP_InternalError::errors_as_string casts the return value of snprintf, which is signed int, to unsigned size_t. So the comparison <= 0 is effectively == 0, ignoring errors.

I don't think snprintf actually returns an error unless the format string is wrong, which it isn't, so this is probably mostly academic. I don't believe the == 0 case is hit anyway, since the loop exits earlier by checking buffer_used >= len.

Also included a micro-optimization to avoid a conditional in the loop.

Note: I am employed by Exyn Technologies

@tridge
Copy link
Contributor

tridge commented May 10, 2024

@durka thanks!
minor thing, our code style requires the commit to start with the subsystem, so:
AP_InternalError: fix signedness issue with snprintf
I can fix your PR if you don't know how to reword a commit

@durka
Copy link
Author

durka commented May 10, 2024

updated the commit message

@peterbarker peterbarker merged commit 8e399cf into ArduPilot:master May 22, 2024
91 checks passed
@peterbarker
Copy link
Contributor

Merged, thanks!

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.

3 participants