xiaoxiang781216 commented on code in PR #21474:
URL: https://github.com/apache/nuttx/pull/21474#discussion_r4477013622
##########
libs/libc/stream/lib_libvsprintf.c:
##########
@@ -403,14 +520,8 @@ static int vsprintf_internal(FAR struct lib_outstream_s
*stream,
}
else
{
- if ((flags & FL_PREC) == 0)
- {
- width = (int)arglist->value[index - 1].u;
- }
- else
- {
- prec = (int)arglist->value[index - 1].u;
- }
+ star = (int)arglist->value[index - 1].u;
Review Comment:
removde the cast?
##########
libs/libc/stream/lib_libvsprintf.c:
##########
@@ -887,10 +1039,10 @@ static int vsprintf_internal(FAR struct lib_outstream_s
*stream,
while (n != -1)
{
int next = n - 1;
- int offset = exp - n;
+ unsigned int offset = (unsigned int)exp - n;
Review Comment:
ditto
##########
libs/libc/stream/lib_libvsprintf.c:
##########
@@ -800,28 +942,38 @@ static int vsprintf_internal(FAR struct lib_outstream_s
*stream,
if ((flags & FL_FLTFIX) != 0)
{
- n = (exp > 0 ? exp + 1 : 1);
+ flen = (exp > 0 ? exp + 1 : 1);
}
else
{
- n = 5; /* 1e+00 */
+ flen = 5; /* 1e+00 */
+ if (exp >= 100 || exp <= -100)
+ {
+ flen++;
+ }
}
if (sign != 0)
{
- n += 1;
+ flen += 1;
}
if (prec != 0)
{
- n += prec + 1;
+ flen += (unsigned int)prec + 1;
Review Comment:
change prec to unisgend and remove the cast?
##########
libs/libc/stream/lib_libvsprintf.c:
##########
@@ -866,7 +1018,7 @@ static int vsprintf_internal(FAR struct lib_outstream_s
*stream,
/* Pull digits from buffer when in-range, otherwise use 0 */
- if (0 <= exp - n && exp - n < ndigs)
+ if ((unsigned int)exp - n < (unsigned int)ndigs)
Review Comment:
why not change exp and ndigs to unsigned in and remove the cast
##########
libs/libc/stream/lib_libvsprintf.c:
##########
@@ -887,10 +1039,10 @@ static int vsprintf_internal(FAR struct lib_outstream_s
*stream,
while (n != -1)
{
int next = n - 1;
- int offset = exp - n;
+ unsigned int offset = (unsigned int)exp - n;
if (next < -prec ||
- (0 <= offset && offset < ndigs &&
+ (offset < (unsigned int)ndigs &&
Review Comment:
ditto
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]