@@ -180,102 +180,6 @@ of _ADD_TO_STRING, as we will resize the buffer if necessary. */
180180 _ADD_TO_STRING ( c );\
181181}
182182
183-
184- /* ++
185- Function :
186-
187- FMTMSG_ProcessPrintf
188-
189- Processes the printf formatters based on the format.
190-
191- Returns the LPWSTR string, or NULL on failure.
192- */
193-
194- static LPWSTR FMTMSG_ProcessPrintf ( WCHAR c ,
195- LPWSTR lpPrintfString,
196- LPWSTR lpInsertString)
197- {
198- LPWSTR lpBuffer = NULL ;
199- LPWSTR lpBuffer2 = NULL ;
200- LPWSTR lpFormat = NULL ;
201- #if _DEBUG
202- // small size for _DEBUG to exercise buffer reallocation logic
203- int tmpSize = 4 ;
204- #else
205- int tmpSize = 64 ;
206- #endif
207- UINT nFormatLength = 0 ;
208- int nBufferLength = 0 ;
209-
210- TRACE ( " FMTMSG_ProcessPrintf( %C, %S, %p )\n " , c,
211- lpPrintfString, lpInsertString );
212-
213- switch ( c )
214- {
215- case ' e' :
216- /* Fall through */
217- case ' E' :
218- /* Fall through */
219- case ' f' :
220- /* Fall through */
221- case ' g' :
222- /* Fall through */
223- case ' G' :
224- ERROR ( " %%%c is not supported by FormatMessage.\n " , c );
225- SetLastError ( ERROR_INVALID_PARAMETER );
226- return NULL ;
227- }
228-
229- nFormatLength = PAL_wcslen ( lpPrintfString ) + 2 ; /* Need to count % AND NULL */
230- lpFormat = (LPWSTR)PAL_malloc ( nFormatLength * sizeof ( WCHAR ) );
231- if ( !lpFormat )
232- {
233- ERROR ( " Unable to allocate memory.\n " );
234- SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
235- return NULL ;
236- }
237- /* Create the format string. */
238- memset ( lpFormat, 0 , nFormatLength * sizeof (WCHAR) );
239- *lpFormat = ' %' ;
240-
241- PAL_wcscat ( lpFormat, lpPrintfString );
242-
243- lpBuffer = (LPWSTR) PAL_malloc (tmpSize*sizeof (WCHAR));
244-
245- /* try until the buffer is big enough */
246- while (TRUE )
247- {
248- if (!lpBuffer)
249- {
250- ERROR (" Unable to allocate memory\n " );
251- SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
252- PAL_free (lpFormat);
253- return NULL ;
254- }
255- nBufferLength = _snwprintf_s ( lpBuffer, tmpSize, tmpSize,
256- lpFormat, lpInsertString);
257-
258- if ((nBufferLength >= 0 ) && (nBufferLength != tmpSize))
259- {
260- break ; /* succeeded */
261- }
262- else
263- {
264- tmpSize *= 2 ;
265- lpBuffer2 = static_cast <WCHAR *>(
266- PAL_realloc (lpBuffer, tmpSize*sizeof (WCHAR)));
267- if (lpBuffer2 == NULL )
268- PAL_free (lpBuffer);
269- lpBuffer = lpBuffer2;
270- }
271- }
272-
273- PAL_free ( lpFormat );
274- lpFormat = NULL ;
275-
276- return lpBuffer;
277- }
278-
279183/* ++
280184Function:
281185 FormatMessageW
@@ -481,113 +385,33 @@ FormatMessageW(
481385 }
482386 if ( *lpSourceString == ' !' )
483387 {
484- LPWSTR lpInsertString = NULL ;
485- LPWSTR lpPrintfString = NULL ;
486- LPWSTR lpStartOfFormattedString = NULL ;
487- UINT nPrintfLength = 0 ;
488- LPWSTR lpFormattedString = NULL ;
489- UINT nFormattedLength = 0 ;
490-
491- if ( !bIsVaList )
492- {
493- lpInsertString = ((LPWSTR*)Arguments)[ Index - 1 ];
494- }
495- else
496- {
497- va_list TheArgs;
498-
499- va_copy (TheArgs, *Arguments);
500- UINT i = 0 ;
501- for ( ; i < Index; i++ )
502- {
503- lpInsertString = va_arg ( TheArgs, LPWSTR );
504- }
505- }
506-
507- /* Calculate the length, and extract the printf string.*/
508- lpSourceString++;
509- {
510- LPWSTR p = PAL_wcschr ( lpSourceString, ' !' );
511-
512- if ( NULL == p )
513- {
514- nPrintfLength = 0 ;
515- }
516- else
517- {
518- nPrintfLength = p - lpSourceString;
519- }
520- }
521-
522- lpPrintfString =
523- (LPWSTR)PAL_malloc ( ( nPrintfLength + 1 ) * sizeof ( WCHAR ) );
524-
525- if ( !lpPrintfString )
526- {
527- ERROR ( " Unable to allocate memory.\n " );
528- SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
529- lpWorkingString = NULL ;
530- nCount = 0 ;
531- goto exit;
532- }
533-
534- PAL_wcsncpy ( lpPrintfString, lpSourceString, nPrintfLength );
535- *( lpPrintfString + nPrintfLength ) = ' \0 ' ;
536-
537- lpStartOfFormattedString = lpFormattedString =
538- FMTMSG_ProcessPrintf ( *lpPrintfString,
539- lpPrintfString,
540- lpInsertString);
541-
542- if ( !lpFormattedString )
543- {
544- ERROR ( " Unable to process the format string.\n " );
545- /* Function will set the error code. */
546- PAL_free ( lpPrintfString );
547- lpWorkingString = NULL ;
548- goto exit;
549- }
550-
551-
552- nFormattedLength = PAL_wcslen ( lpFormattedString );
553-
554- /* Append the processed printf string into the working string */
555- while ( *lpFormattedString )
556- {
557- _CHECKED_ADD_TO_STRING ( *lpFormattedString );
558- lpFormattedString++;
559- }
388+ ERROR ( " Embedded printf formatting ('!<printf format>!') is unsupported\n " );
389+ SetLastError ( ERROR_INVALID_PARAMETER );
390+ lpWorkingString = NULL ;
391+ nCount = 0 ;
392+ goto exit;
393+ }
560394
561- lpSourceString += nPrintfLength + 1 ;
562- PAL_free ( lpPrintfString );
563- PAL_free ( lpStartOfFormattedString );
564- lpPrintfString = lpFormattedString = NULL ;
395+ LPWSTR lpInsert = NULL ;
396+ if ( !bIsVaList )
397+ {
398+ lpInsert = ((LPWSTR*)Arguments)[Index - 1 ] ;
565399 }
566400 else
567401 {
568- /* The printf format string defaults to 's'.*/
569- LPWSTR lpInsert = NULL ;
570-
571- if ( !bIsVaList )
572- {
573- lpInsert = ((LPWSTR*)Arguments)[Index - 1 ];
574- }
575- else
402+ va_list TheArgs;
403+ va_copy (TheArgs, *Arguments);
404+ UINT i = 0 ;
405+ for ( ; i < Index; i++ )
576406 {
577- va_list TheArgs;
578- va_copy (TheArgs, *Arguments);
579- UINT i = 0 ;
580- for ( ; i < Index; i++ )
581- {
582- lpInsert = va_arg ( TheArgs, LPWSTR );
583- }
407+ lpInsert = va_arg ( TheArgs, LPWSTR );
584408 }
409+ }
585410
586- while ( *lpInsert )
587- {
588- _CHECKED_ADD_TO_STRING ( *lpInsert );
589- lpInsert++;
590- }
411+ while ( *lpInsert )
412+ {
413+ _CHECKED_ADD_TO_STRING ( *lpInsert );
414+ lpInsert++;
591415 }
592416 }
593417 /* Format specifiers. */
0 commit comments