AtlTraceVA

I'm hitting a runtime error in my debug builds. I've traced it down to AtlTraceVA (atldebugapi.cpp). It looks like a buffer overflow. Here's a code snipet

void__cdecl AtlTraceVA(DWORD_PTR dwModule,constchar *pszFileName,int nLine,

DWORD_PTR dwCategory, UINT nLevel,const CHAR *pszFormat, va_list ptr)

{

...
staticconstint nCount = 1024;

CHAR szBuf[nCount] = {'\0'};

...
}

Shouldn't be

CHAR szBuf[nCount-1] = {'\0'};

[1193 byte] By [cgreathouse] at [2007-12-17]
# 1
No! The code is correct.

CHAR szBuf[nCount]; Would allocate a buffer of 1kb size.

CHAR szBuf[nCount] = {'\0'};
Allocates the buffer of 1kb size and initializes the first CHAR of the buffer to '\0'!
That's all. Its not an assignment to the char behind the last in the array!

MartinRichter at 2007-9-8 > top of Msdn Tech,Visual C++,Visual C++ General...