Skip to content

[BUG] 学习过程中看到的一些问题 #3

Description

@peixinchen
template<typename T>
inlinevoidSerializer::output_type(T& t)
{
int len = sizeof(T);
char* d = newchar[len];
if (!m_iodevice.is_eof()){
memcpy(d, m_iodevice.current(), len);
m_iodevice.offset(len);
byte_orser(d, len);
t = *reinterpret_cast<T*>(&d[0]);
}
delete [] d;
}
  1. if (!m_iodevice.is_eof()){ 这里有越界风险,current 没有越界,但 current + size 不保证不会越界;

  2. char *d = new char[len]; 有内存泄漏的情况,没有 delete 的时机

  3. 有太多次的 memcpy 了,从socket 到 vector,再到这里的 d buffer,然后 copy 到变量 T

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions