Skip to content

Commit 68f9e6e

Browse files
committed
Improvement from code review
1 parent 17b98c1 commit 68f9e6e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/CLR/Helpers/nanoprintf/nanoprintf.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,15 +1221,19 @@ printf_t sprintf_(char *buf, const char *fmt, ... )
12211221
printf_t snprintf_(char *buf, size_t n,const char *fmt, ... )
12221222
{
12231223
va_list ap;
1224-
int Count;
1224+
int count;
12251225

12261226
va_start(ap, fmt);
1227-
Count = doprnt(&buf, putbuf, n, fmt, ap);
1227+
count = doprnt(&buf, putbuf, n - 1, fmt, ap);
12281228
va_end(ap);
1229-
// Append null terminator.
1230-
*buf = '\0';
1229+
1230+
// Append null terminator if there's space.
1231+
if (n > 0)
1232+
{
1233+
*buf = '\0';
1234+
}
12311235

1232-
return Count;
1236+
return count;
12331237
}
12341238
// [END_NF_CHANGE]
12351239

0 commit comments

Comments
 (0)