Skip to content

Commit 70473c1

Browse files
HelderMagalhaesColin Robertson
authored andcommitted
Typo in "Important" section (MicrosoftDocs#180)
1 parent c6ec43b commit 70473c1

File tree

1 file changed

+170
-170
lines changed

1 file changed

+170
-170
lines changed

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

Lines changed: 170 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -19,173 +19,173 @@ author: "corob-msft"
1919
ms.author: "corob"
2020
manager: "ghogen"
2121
ms.workload: ["cplusplus"]
22-
---
23-
# vsprintf, _vsprintf_l, vswprintf, _vswprintf_l, __vswprintf_l
24-
Write formatted output using a pointer to a list of arguments. More secure versions of these functions are available; see [vsprintf_s, _vsprintf_s_l, vswprintf_s, _vswprintf_s_l](../../c-runtime-library/reference/vsprintf-s-vsprintf-s-l-vswprintf-s-vswprintf-s-l.md).
25-
26-
## Syntax
27-
28-
```
29-
int vsprintf(
30-
char *buffer,
31-
const char *format,
32-
va_list argptr
33-
);
34-
int _vsprintf_l(
35-
char *buffer,
36-
const char *format,
37-
locale_t locale,
38-
va_list argptr
39-
);
40-
int vswprintf(
41-
wchar_t *buffer,
42-
size_t count,
43-
const wchar_t *format,
44-
va_list argptr
45-
);
46-
int _vswprintf_l(
47-
wchar_t *buffer,
48-
size_t count,
49-
const wchar_t *format,
50-
locale_t locale,
51-
va_list argptr
52-
);
53-
int __vswprintf_l(
54-
wchar_t *buffer,
55-
const wchar_t *format,
56-
locale_t locale,
57-
va_list argptr
58-
);
59-
template <size_t size>
60-
int vsprintf(
61-
char (&buffer)[size],
62-
const char *format,
63-
va_list argptr
64-
); // C++ only
65-
template <size_t size>
66-
int _vsprintf_l(
67-
char (&buffer)[size],
68-
const char *format,
69-
locale_t locale,
70-
va_list argptr
71-
); // C++ only
72-
template <size_t size>
73-
int vswprintf(
74-
wchar_t (&buffer)[size],
75-
const wchar_t *format,
76-
va_list argptr
77-
); // C++ only
78-
template <size_t size>
79-
int _vswprintf_l(
80-
wchar_t (&buffer)[size],
81-
const wchar_t *format,
82-
locale_t locale,
83-
va_list argptr
84-
); // C++ only
85-
```
86-
87-
#### Parameters
88-
`buffer`
89-
Storage location for output.
90-
91-
`count`
92-
Maximum number of characters to store, in the `UNICODE` version of this function.
93-
94-
`format`
95-
Format specification.
96-
97-
`argptr`
98-
Pointer to list of arguments.
99-
100-
`locale`
101-
The locale to use.
102-
103-
## Return Value
104-
`vsprintf` and `vswprintf` return the number of characters written, not including the terminating null character, or a negative value if an output error occurs. If `buffer` or `format` is a null pointer, these functions invoke the invalid parameter handler, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, these functions return -1 and set `errno` to `EINVAL`.
105-
106-
For information on these and other error codes, see [_doserrno, errno, _sys_errlist, and _sys_nerr](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md).
107-
108-
## Remarks
109-
Each of these functions takes a pointer to an argument list, and then formats and writes the given data to the memory pointed to by `buffer`.
110-
111-
The versions of these functions with the `_l` suffix are identical except that they use the locale parameter passed in instead of the current thread locale.
112-
113-
> [!IMPORTANT]
114-
> Using `vsprintf`, here is no way to limit the number of characters written, which means that code using this function is susceptible to buffer overruns. Use [_vsnprintf](../../c-runtime-library/reference/vsnprintf-vsnprintf-vsnprintf-l-vsnwprintf-vsnwprintf-l.md) instead, or call [_vscprintf](../../c-runtime-library/reference/vscprintf-vscprintf-l-vscwprintf-vscwprintf-l.md) to determine how large a buffer is needed. Also, ensure that `format` is not a user-defined string. For more information, see [Avoiding Buffer Overruns](http://msdn.microsoft.com/library/windows/desktop/ms717795).
115-
116-
`vswprintf` conforms to the ISO C Standard, which requires the second parameter, `count`, of type `size_t`. To force the old nonstandard behavior, define `_CRT_NON_CONFORMING_SWPRINTFS.` The old behavior may not be in a future version, so code should be changed to use the new conformant behavior.
117-
118-
In C++, these functions have template overloads that invoke the newer, secure counterparts of these functions. For more information, see [Secure Template Overloads](../../c-runtime-library/secure-template-overloads.md).
119-
120-
### Generic-Text Routine Mappings
121-
122-
|TCHAR.H routine|_UNICODE & _MBCS not defined|_MBCS defined|_UNICODE defined|
123-
|---------------------|------------------------------------|--------------------|-----------------------|
124-
|`_vstprintf`|`vsprintf`|`vsprintf`|`vswprintf`|
125-
|`_vstprintf_l`|`_vsprintf_l`|`_vsprintf_l`|`_vswprintf_l`|
126-
127-
## Requirements
128-
129-
|Routine|Required header|Optional headers|
130-
|-------------|---------------------|----------------------|
131-
|`vsprintf`, `_vsprintf_l`|\<stdio.h> and \<stdarg.h>|\<varargs.h>*|
132-
|`vswprintf`, `_vswprintf_l`|\<stdio.h> or \<wchar.h>, and \<stdarg.h>|\<varargs.h>*|
133-
134-
\* Required for UNIX V compatibility.
135-
136-
For additional compatibility information, see [Compatibility](../../c-runtime-library/compatibility.md) in the Introduction.
137-
138-
## Example
139-
140-
```
141-
// crt_vsprintf.c
142-
// compile with: /W3
143-
// This program uses vsprintf to write to a buffer.
144-
// The size of the buffer is determined by _vscprintf.
145-
146-
#include <stdlib.h>
147-
#include <stdio.h>
148-
#include <stdarg.h>
149-
150-
void test( char * format, ... )
151-
{
152-
va_list args;
153-
int len;
154-
char *buffer;
155-
156-
// retrieve the variable arguments
157-
va_start( args, format );
158-
159-
len = _vscprintf( format, args ) // _vscprintf doesn't count
160-
+ 1; // terminating '\0'
161-
162-
buffer = (char*)malloc( len * sizeof(char) );
163-
164-
vsprintf( buffer, format, args ); // C4996
165-
// Note: vsprintf is deprecated; consider using vsprintf_s instead
166-
puts( buffer );
167-
168-
free( buffer );
169-
va_end( args );
170-
}
171-
172-
int main( void )
173-
{
174-
test( "%d %c %d", 123, '<', 456 );
175-
test( "%s", "This is a string" );
176-
}
177-
```
178-
179-
```Output
180-
123 < 456
181-
This is a string
182-
```
183-
184-
## See Also
185-
[Stream I/O](../../c-runtime-library/stream-i-o.md)
186-
[vprintf Functions](../../c-runtime-library/vprintf-functions.md)
187-
[Format Specification Syntax: printf and wprintf Functions](../../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)
188-
[fprintf, _fprintf_l, fwprintf, _fwprintf_l](../../c-runtime-library/reference/fprintf-fprintf-l-fwprintf-fwprintf-l.md)
189-
[printf, _printf_l, wprintf, _wprintf_l](../../c-runtime-library/reference/printf-printf-l-wprintf-wprintf-l.md)
190-
[sprintf, _sprintf_l, swprintf, _swprintf_l, \__swprintf_l](../../c-runtime-library/reference/sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)
191-
[va_arg, va_copy, va_end, va_start](../../c-runtime-library/reference/va-arg-va-copy-va-end-va-start.md)
22+
---
23+
# vsprintf, _vsprintf_l, vswprintf, _vswprintf_l, __vswprintf_l
24+
Write formatted output using a pointer to a list of arguments. More secure versions of these functions are available; see [vsprintf_s, _vsprintf_s_l, vswprintf_s, _vswprintf_s_l](../../c-runtime-library/reference/vsprintf-s-vsprintf-s-l-vswprintf-s-vswprintf-s-l.md).
25+
26+
## Syntax
27+
28+
```
29+
int vsprintf(
30+
char *buffer,
31+
const char *format,
32+
va_list argptr
33+
);
34+
int _vsprintf_l(
35+
char *buffer,
36+
const char *format,
37+
locale_t locale,
38+
va_list argptr
39+
);
40+
int vswprintf(
41+
wchar_t *buffer,
42+
size_t count,
43+
const wchar_t *format,
44+
va_list argptr
45+
);
46+
int _vswprintf_l(
47+
wchar_t *buffer,
48+
size_t count,
49+
const wchar_t *format,
50+
locale_t locale,
51+
va_list argptr
52+
);
53+
int __vswprintf_l(
54+
wchar_t *buffer,
55+
const wchar_t *format,
56+
locale_t locale,
57+
va_list argptr
58+
);
59+
template <size_t size>
60+
int vsprintf(
61+
char (&buffer)[size],
62+
const char *format,
63+
va_list argptr
64+
); // C++ only
65+
template <size_t size>
66+
int _vsprintf_l(
67+
char (&buffer)[size],
68+
const char *format,
69+
locale_t locale,
70+
va_list argptr
71+
); // C++ only
72+
template <size_t size>
73+
int vswprintf(
74+
wchar_t (&buffer)[size],
75+
const wchar_t *format,
76+
va_list argptr
77+
); // C++ only
78+
template <size_t size>
79+
int _vswprintf_l(
80+
wchar_t (&buffer)[size],
81+
const wchar_t *format,
82+
locale_t locale,
83+
va_list argptr
84+
); // C++ only
85+
```
86+
87+
#### Parameters
88+
`buffer`
89+
Storage location for output.
90+
91+
`count`
92+
Maximum number of characters to store, in the `UNICODE` version of this function.
93+
94+
`format`
95+
Format specification.
96+
97+
`argptr`
98+
Pointer to list of arguments.
99+
100+
`locale`
101+
The locale to use.
102+
103+
## Return Value
104+
`vsprintf` and `vswprintf` return the number of characters written, not including the terminating null character, or a negative value if an output error occurs. If `buffer` or `format` is a null pointer, these functions invoke the invalid parameter handler, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, these functions return -1 and set `errno` to `EINVAL`.
105+
106+
For information on these and other error codes, see [_doserrno, errno, _sys_errlist, and _sys_nerr](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md).
107+
108+
## Remarks
109+
Each of these functions takes a pointer to an argument list, and then formats and writes the given data to the memory pointed to by `buffer`.
110+
111+
The versions of these functions with the `_l` suffix are identical except that they use the locale parameter passed in instead of the current thread locale.
112+
113+
> [!IMPORTANT]
114+
> Using `vsprintf`, there is no way to limit the number of characters written, which means that code using this function is susceptible to buffer overruns. Use [_vsnprintf](../../c-runtime-library/reference/vsnprintf-vsnprintf-vsnprintf-l-vsnwprintf-vsnwprintf-l.md) instead, or call [_vscprintf](../../c-runtime-library/reference/vscprintf-vscprintf-l-vscwprintf-vscwprintf-l.md) to determine how large a buffer is needed. Also, ensure that `format` is not a user-defined string. For more information, see [Avoiding Buffer Overruns](http://msdn.microsoft.com/library/windows/desktop/ms717795).
115+
116+
`vswprintf` conforms to the ISO C Standard, which requires the second parameter, `count`, of type `size_t`. To force the old nonstandard behavior, define `_CRT_NON_CONFORMING_SWPRINTFS.` The old behavior may not be in a future version, so code should be changed to use the new conformant behavior.
117+
118+
In C++, these functions have template overloads that invoke the newer, secure counterparts of these functions. For more information, see [Secure Template Overloads](../../c-runtime-library/secure-template-overloads.md).
119+
120+
### Generic-Text Routine Mappings
121+
122+
|TCHAR.H routine|_UNICODE & _MBCS not defined|_MBCS defined|_UNICODE defined|
123+
|---------------------|------------------------------------|--------------------|-----------------------|
124+
|`_vstprintf`|`vsprintf`|`vsprintf`|`vswprintf`|
125+
|`_vstprintf_l`|`_vsprintf_l`|`_vsprintf_l`|`_vswprintf_l`|
126+
127+
## Requirements
128+
129+
|Routine|Required header|Optional headers|
130+
|-------------|---------------------|----------------------|
131+
|`vsprintf`, `_vsprintf_l`|\<stdio.h> and \<stdarg.h>|\<varargs.h>*|
132+
|`vswprintf`, `_vswprintf_l`|\<stdio.h> or \<wchar.h>, and \<stdarg.h>|\<varargs.h>*|
133+
134+
\* Required for UNIX V compatibility.
135+
136+
For additional compatibility information, see [Compatibility](../../c-runtime-library/compatibility.md) in the Introduction.
137+
138+
## Example
139+
140+
```
141+
// crt_vsprintf.c
142+
// compile with: /W3
143+
// This program uses vsprintf to write to a buffer.
144+
// The size of the buffer is determined by _vscprintf.
145+
146+
#include <stdlib.h>
147+
#include <stdio.h>
148+
#include <stdarg.h>
149+
150+
void test( char * format, ... )
151+
{
152+
va_list args;
153+
int len;
154+
char *buffer;
155+
156+
// retrieve the variable arguments
157+
va_start( args, format );
158+
159+
len = _vscprintf( format, args ) // _vscprintf doesn't count
160+
+ 1; // terminating '\0'
161+
162+
buffer = (char*)malloc( len * sizeof(char) );
163+
164+
vsprintf( buffer, format, args ); // C4996
165+
// Note: vsprintf is deprecated; consider using vsprintf_s instead
166+
puts( buffer );
167+
168+
free( buffer );
169+
va_end( args );
170+
}
171+
172+
int main( void )
173+
{
174+
test( "%d %c %d", 123, '<', 456 );
175+
test( "%s", "This is a string" );
176+
}
177+
```
178+
179+
```Output
180+
123 < 456
181+
This is a string
182+
```
183+
184+
## See Also
185+
[Stream I/O](../../c-runtime-library/stream-i-o.md)
186+
[vprintf Functions](../../c-runtime-library/vprintf-functions.md)
187+
[Format Specification Syntax: printf and wprintf Functions](../../c-runtime-library/format-specification-syntax-printf-and-wprintf-functions.md)
188+
[fprintf, _fprintf_l, fwprintf, _fwprintf_l](../../c-runtime-library/reference/fprintf-fprintf-l-fwprintf-fwprintf-l.md)
189+
[printf, _printf_l, wprintf, _wprintf_l](../../c-runtime-library/reference/printf-printf-l-wprintf-wprintf-l.md)
190+
[sprintf, _sprintf_l, swprintf, _swprintf_l, \__swprintf_l](../../c-runtime-library/reference/sprintf-sprintf-l-swprintf-swprintf-l-swprintf-l.md)
191+
[va_arg, va_copy, va_end, va_start](../../c-runtime-library/reference/va-arg-va-copy-va-end-va-start.md)

0 commit comments

Comments
 (0)