ardupilot icon indicating copy to clipboard operation
ardupilot copied to clipboard

Fix signedness issue with snprintf

Open durka opened this issue 1 year ago • 2 comments

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

durka avatar May 09 '24 14:05 durka

@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

tridge avatar May 10 '24 02:05 tridge

updated the commit message

durka avatar May 10 '24 15:05 durka

Merged, thanks!

peterbarker avatar May 22 '24 13:05 peterbarker