X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdio%2Fvsnprintf.c;h=06536d177ff5e84c4765ff3c120caa7bc62a8242;hp=9eb869e78cb2b7dbb52c9eab259b0fba1670283c;hb=f6b6a83981cda2a6f20a945631be2d9a7a257192;hpb=715fe6b88a65aad9123e44860fef880700e7167d diff --git a/functions/stdio/vsnprintf.c b/functions/stdio/vsnprintf.c index 9eb869e..06536d1 100644 --- a/functions/stdio/vsnprintf.c +++ b/functions/stdio/vsnprintf.c @@ -32,7 +32,12 @@ int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restric if ( ( *format != '%' ) || ( ( rc = _PDCLIB_print( format, &status ) ) == format ) ) { /* No conversion specifier, print verbatim */ - s[ status.i++ ] = *(format++); + if ( status.i < n ) + { + s[ status.i ] = *format; + } + status.i++; + format++; } else { @@ -40,7 +45,10 @@ int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restric format = rc; } } - s[ status.i ] = '\0'; + if ( status.i < n ) + { + s[ status.i ] = '\0'; + } va_end( status.arg ); return status.i; }