Please help me understand - why am I getting this run-time error:
*** stack smashing detected ***:
Program received signal SIGABRT, Aborted.
for the following code :
#define WORD_SIZE (sizeof(int))
#define FLOOR_MASK 0xfffffffc
static void SetVal(void* _block, int _size)
{
*(int*)_block = _size;
}
void BufferInit(void* _buffer, size_t _totalSize)
{
int alignedSize;
assert(_buffer);
/* align _totalSize to be WORD_SIZE multiple */
alignedSize = _totalSize & FLOOR_MASK;
/* mark end of buffer */
SetVal(_buffer + alignedSize, END_VAL);
}
int main()
{
Byte buffer[36];
BufferInit(buffer, 37);
return 0;
}
P.S: The error occurs at the end of the run (on line "return 0;"
).
Thanks.