buttonrpc_cpp14 icon indicating copy to clipboard operation
buttonrpc_cpp14 copied to clipboard

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

Open peixinchen opened this issue 6 years ago • 1 comments

template<typename T>
inline void Serializer::output_type(T& t)
{
	int len = sizeof(T);
	char* d = new char[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

peixinchen avatar Jan 24 '19 06:01 peixinchen

好,我试试看

madadaaa avatar May 13 '20 08:05 madadaaa