Skip to content

Commit eec253e

Browse files
Merge pull request MicrosoftDocs#2291 from corob-msft/cr-1541
Update vsprintf sample to address 1541
2 parents 38bfcca + d68c6ce commit eec253e

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

docs/c-runtime-library/reference/vsprintf-vsprintf-l-vswprintf-vswprintf-l-vswprintf-l.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "vsprintf, _vsprintf_l, vswprintf, _vswprintf_l, __vswprintf_l"
3-
ms.date: "11/04/2016"
3+
ms.date: "09/03/2019"
44
apiname: ["_vswprintf_l", "_vsprintf_l", "vsprintf", "vswprintf", "__vswprintf_l"]
55
apilocation: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "ntoskrnl.exe"]
66
apitype: "DLLExport"
@@ -75,19 +75,19 @@ int _vswprintf_l(
7575

7676
### Parameters
7777

78-
*buffer*<br/>
78+
*buffer*\
7979
Storage location for output.
8080

81-
*count*<br/>
81+
*count*\
8282
Maximum number of characters to store, in the wide string versions of this function.
8383

84-
*format*<br/>
84+
*format*\
8585
Format specification.
8686

87-
*argptr*<br/>
87+
*argptr*\
8888
Pointer to list of arguments.
8989

90-
*locale*<br/>
90+
*locale*\
9191
The locale to use.
9292

9393
## Return Value
@@ -131,15 +131,16 @@ For additional compatibility information, see [Compatibility](../../c-runtime-li
131131

132132
```C
133133
// crt_vsprintf.c
134-
// compile with: /W3
134+
// compile with: cl /W4 crt_vsprintf.c
135135
// This program uses vsprintf to write to a buffer.
136136
// The size of the buffer is determined by _vscprintf.
137137

138+
#define _CRT_SECURE_NO_WARNINGS
138139
#include <stdlib.h>
139140
#include <stdio.h>
140141
#include <stdarg.h>
141142

142-
void test( char * format, ... )
143+
void test( char const * const format, ... )
143144
{
144145
va_list args;
145146
int len;
@@ -152,12 +153,14 @@ void test( char * format, ... )
152153
+ 1; // terminating '\0'
153154

154155
buffer = (char*)malloc( len * sizeof(char) );
155-
156-
vsprintf( buffer, format, args ); // C4996
157-
// Note: vsprintf is deprecated; consider using vsprintf_s instead
158-
puts( buffer );
159-
160-
free( buffer );
156+
if ( 0 != buffer )
157+
{
158+
vsprintf( buffer, format, args ); // C4996
159+
// Note: vsprintf is deprecated; consider using vsprintf_s instead
160+
puts( buffer );
161+
162+
free( buffer );
163+
}
161164
va_end( args );
162165
}
163166

@@ -175,10 +178,10 @@ This is a string
175178

176179
## See also
177180

178-
[Stream I/O](../../c-runtime-library/stream-i-o.md)<br/>
179-
[vprintf Functions](../../c-runtime-library/vprintf-functions.md)<br/>
180-
[Format Specification Syntax: printf and wprintf Functions](../../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)<br/>
181-
[fprintf, _fprintf_l, fwprintf, _fwprintf_l](fprintf-fprintf-l-fwprintf-fwprintf-l.md)<br/>
182-
[printf, _printf_l, wprintf, _wprintf_l](printf-printf-l-wprintf-wprintf-l.md)<br/>
183-
[sprintf, _sprintf_l, swprintf, _swprintf_l, \__swprintf_l](sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)<br/>
184-
[va_arg, va_copy, va_end, va_start](va-arg-va-copy-va-end-va-start.md)<br/>
181+
[Stream I/O](../../c-runtime-library/stream-i-o.md)\
182+
[vprintf Functions](../../c-runtime-library/vprintf-functions.md)\
183+
[Format Specification Syntax: printf and wprintf Functions](../../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)\
184+
[fprintf, _fprintf_l, fwprintf, _fwprintf_l](fprintf-fprintf-l-fwprintf-fwprintf-l.md)\
185+
[printf, _printf_l, wprintf, _wprintf_l](printf-printf-l-wprintf-wprintf-l.md)\
186+
[sprintf, _sprintf_l, swprintf, _swprintf_l, \__swprintf_l](sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)\
187+
[va_arg, va_copy, va_end, va_start](va-arg-va-copy-va-end-va-start.md)

0 commit comments

Comments
 (0)