Partager via


C6255

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

warning C6255: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead

This warning indicates that a call to _alloca has been detected outside of local exception handling. _alloca should always be called from within the protected range of an exception handler because it can raise a stack overflow exception on failure. If possible, instead of using _alloca, consider using _malloca which is a more secure version of _alloca.

Example

The following code generates this warning because _alloca can generate exception:

#include <windows.h>  
  
void f( )  
{  
  void *p = _alloca(10);  
  // code ...  
}  
  

To correct this warning, use _malloca and add exception handler as shown in the following code:

#include <windows.h>  
#include <malloc.h>  
  
void f( )  
{  
  void *p;  
  int errcode;  
  __try   
  {  
    p = _malloca(10);  
    // code...  
    _freea(p);  
  }  
  __except( (GetExceptionCode() == STATUS_STACK_OVERFLOW ) ?  
              EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH )  
  {  
    errcode = _resetstkoflw();  
    // code ...  
  }  
}  

See Also

_malloca