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

Misra compliance #79

Closed
wants to merge 13 commits into from
6 changes: 4 additions & 2 deletions src/printf/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,9 @@ static size_t print_broken_up_decimal(
}
}
// add extra 0s
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) {
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count > 0U)) {
buf[len++] = '0';
--count;
}
if (len < PRINTF_FTOA_BUFFER_SIZE) {
buf[len++] = '.';
Expand Down Expand Up @@ -1055,8 +1056,9 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
}
}
// string output
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this exactly equivalent?

What if there are no precision flags? In that case, with the new code, precision gets decremented while before it wasn't.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, but precision is only used to exit the while loop, so this does not impact any functionality.

out(*(p++), buffer, idx++, maxlen);
--precision;
}
// post padding
if (flags & FLAGS_LEFT) {
Expand Down