Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
C6255
Collapse the table of content
Expand the table of content

C6255

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 ...
  }
}
Show:
© 2015 Microsoft