Skip to content

Latest commit

 

History

History
166 lines (115 loc) · 5.01 KB

crtsetdebugfillthreshold.md

File metadata and controls

166 lines (115 loc) · 5.01 KB
title description ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords ms.assetid
_CrtSetDebugFillThreshold
Use the _CrtSetDebugFillThreshold function to set the maximum amount of buffer to fill in secure CRT functions.
10/31/2019
_CrtSetDebugFillThreshold
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
DLLExport
apiref
_CrtSetDebugFillThreshold
CrtSetDebugFillThreshold
debug, buffer-filling behavior
CrtSetDebugFillThreshold function
_CrtSetDebugFillThreshold function
buffer-filling behavior
0xFE
6cb360e8-56ae-4248-b17f-e28aee3e0ed7

_CrtSetDebugFillThreshold

Retrieves or modifies the threshold controlling buffer-filling behavior in debug functions.

Syntax

size_t _CrtSetDebugFillThreshold( size_t newThreshold );

Parameters

newThreshold
New threshold size in bytes.

Return value

The previous threshold value.

Remarks

The debug versions of some security-enhanced CRT functions fill the buffer passed to them with a special character (0xFE). This fill character helps to find cases where the incorrect size was passed to the function. Unfortunately, it also reduces performance. To improve performance, use _CrtSetDebugFillThreshold to disable buffer-filling for buffers larger than the newThreshold threshold. A newThreshold value of 0 disables it for all buffers.

The default threshold is SIZE_T_MAX.

Here's a list of the affected functions:

Requirements

Routine Required header
_CrtSetDebugFillThreshold <crtdbg.h>

This function is Microsoft-specific. For more compatibility information, see Compatibility.

Libraries

Debug versions of the C run-time libraries only.

Example

// crt_crtsetdebugfillthreshold.c
// compile with: cl /MTd crt_crtsetdebugfillthreshold.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crtdbg.h>

void Clear( char buff[], size_t size )
{
   for( int i=0; i<size; ++i )
      buff[i] = 0;
}

void Print( char buff[], size_t size )
{
   for( int i=0; i<size; ++i )
      printf( "%02x  %c\n", (unsigned char)buff[i], buff[i] );
}

int main( void )
{
   char buff[10];

   printf( "With buffer-filling on:\n" );
   strcpy_s( buff, _countof(buff), "howdy" );
   Print( buff, _countof(buff) );

   _CrtSetDebugFillThreshold( 0 );

   printf( "With buffer-filling off:\n" );
   Clear( buff, _countof(buff) );
   strcpy_s( buff, _countof(buff), "howdy" );
   Print( buff, _countof(buff) );
}
With buffer-filling on:
68  h
6f  o
77  w
64  d
79  y
00
fe  ■
fe  ■
fe  ■
fe  ■
With buffer-filling off:
68  h
6f  o
77  w
64  d
79  y
00
00
00
00
00

See also

Debug routines