C6255

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see C6255 on docs.microsoft.com. 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.

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 ...  
  }  
}  

_malloca

Show: