warning C6386: Buffer overrun while writing to 'this->m_csSounds[byIndex].szSound': the...

  • Thread starter Thread starter Chuckie72
  • Start date Start date
C

Chuckie72

Guest
I have this code:

DWORD CButtonST::SetSound(LPCTSTR lpszSound, HMODULE hMod, BOOL bPlayOnClick, BOOL bPlayAsync)
{
BYTE byIndex = bPlayOnClick ? 1 : 0;

// Store new sound
if (lpszSound)
{
if (hMod) // From resource identifier ?
{
m_csSounds[byIndex].lpszSound = lpszSound;
} // if
else
{
_tcscpy_s(m_csSounds[byIndex].szSound,
sizeof(m_csSounds[byIndex].szSound), lpszSound);
m_csSounds[byIndex].lpszSound = m_csSounds[byIndex].szSound;
} // else

m_csSounds[byIndex].hMod = hMod;
m_csSounds[byIndex].dwFlags = SND_NODEFAULT | SND_NOWAIT;
m_csSounds[byIndex].dwFlags |= hMod ? SND_RESOURCE : SND_FILENAME;
m_csSounds[byIndex].dwFlags |= bPlayAsync ? SND_ASYNC : SND_SYNC;
} // if
else
{
// Or remove any existing
::ZeroMemory(&m_csSounds[byIndex], sizeof(STRUCT_SOUND));
} // else

return BTNST_OK;
} // End of SetSound

When I run the code analysis I get this warning:

warning C6386: Buffer overrun while writing to this->m_csSounds[byIndex].szSound: the writable size is 520 bytes, but 1040 bytes might be written.

So it is complaining about this bit:

_tcscpy_s(m_csSounds[byIndex].szSound,
sizeof(m_csSounds[byIndex].szSound), lpszSound);


m_csSounds is a structure:

typedef struct _STRUCT_SOUND
{
TCHAR szSound[_MAX_PATH];
LPCTSTR lpszSound;
HMODULE hMod;
DWORD dwFlags;
} STRUCT_SOUND;



How can I resolve this warning, or is it a false positive?

Continue reading...
 
Back
Top