pkarashchenko commented on code in PR #7716: URL: https://github.com/apache/nuttx/pull/7716#discussion_r1033268931
########## libs/libc/stdio/lib_libvsprintf.c: ########## @@ -878,26 +879,27 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream, /* Parse the ndigs if the value of it bigger than '9' */ - while (1) + if (ndigs >= '0') { - if (ndigs >= 'd') + ndigs -= '0'; + __ultoa_invert(ndigs, (FAR char *) buf, 10); Review Comment: ```suggestion __ultoa_invert(ndigs, (FAR char *)buf, 10); ``` ########## libs/libc/stdio/lib_libvsprintf.c: ########## @@ -878,26 +879,27 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream, /* Parse the ndigs if the value of it bigger than '9' */ - while (1) + if (ndigs >= '0') { - if (ndigs >= 'd') + ndigs -= '0'; + __ultoa_invert(ndigs, (FAR char *) buf, 10); + if (ndigs >= 100) { - lib_stream_put(stream, ((ndigs - '0') / 100) + '0'); - ndigs = (ndigs - '0') % 100 + '0'; - } - else if (ndigs >= ':') - { - lib_stream_put(stream, ((ndigs - '0') / 10) + '0'); - ndigs = (ndigs - '0') % 10 + '0'; + for (int i = 2; i >= 0; i--) + { + lib_stream_put(stream, buf[i]); + } } - else if(ndigs >= '0') + else if (ndigs >= 10 && ndigs < 100) { - lib_stream_put(stream, ndigs); - break; + for (int i = 1; i >= 0; i--) Review Comment: ```suggestion int i; for (int i = 1; i >= 0; i--) ``` ########## libs/libc/stdio/lib_libvsprintf.c: ########## @@ -878,26 +879,27 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream, /* Parse the ndigs if the value of it bigger than '9' */ - while (1) + if (ndigs >= '0') { - if (ndigs >= 'd') + ndigs -= '0'; + __ultoa_invert(ndigs, (FAR char *) buf, 10); + if (ndigs >= 100) { - lib_stream_put(stream, ((ndigs - '0') / 100) + '0'); - ndigs = (ndigs - '0') % 100 + '0'; - } - else if (ndigs >= ':') - { - lib_stream_put(stream, ((ndigs - '0') / 10) + '0'); - ndigs = (ndigs - '0') % 10 + '0'; + for (int i = 2; i >= 0; i--) Review Comment: ```suggestion int i; for (i = 2; i >= 0; i--) ``` can also go with something like ``` c = 2; while (c) { lib_stream_put(stream, buf[--c]); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org