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.
Remarks
_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
.
Code analysis name: UNPROTECTEDUSEOFALLOCA
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 ...
}
}