In memcpy_s function, Is taking destSize as sizeof(m_pDataToSend) is correct?

  • Thread starter Thread starter David student
  • Start date Start date
D

David student

Guest
Hello all,

I replaced memcpy with memcpy_s as memcpy is a banned function and wanted to know the parameter values passed in memcpy_s are correct?

memcpy_s function has below parameters:

dest (this is of BYTE *)
destSize (this is sizeof(Byte pointer variable)
src (this is also of type BYTE *)
count (passing the size)

Is taking destSize as sizeof(m_pDataToSend) is correct?

bool ERHttpClient::SetDataToSend(BYTE *data, unsigned int dataSize)
{
if (data == NULL || dataSize < 0)
{
return false;
}

if (m_pDataToSend != NULL)
{
delete[] m_pDataToSend;
}
m_pDataToSend = NULL;
m_pDataToSend = new BYTE[dataSize];
if (m_pDataToSend != NULL)
{
// memcpy(m_pDataToSend, data, dataSize);
memcpy_s(m_pDataToSend, sizeof(m_pDataToSend), data, dataSize);
m_dataToSendSize = dataSize;
return true;
}

return false;
}

m_pDataToSend is declared like as shown below:

BYTE *m_pDataToSend;

And also in an another function I am doing like as shown below for memcpy_s:

unsigned int iCurrentBufferSize = 0;
BYTE *pOldBuffer = m_pResponse;
BYTE *pResponse = new BYTE[dwSize + 1];
DWORD dwRead = 0;

memcpy_s(m_pResponse + iCurrentBufferSize, sizeof(m_pResponse + iCurrentBufferSize), pResponse, dwRead);

In the above memcpy_s function also is second parameter is correct?

Thank you in advance.

Continue reading...
 
Back
Top