Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

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 ...
  }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.