Quellcode durchsuchen

core: add self-assignment check

Daniele Bartolini vor 3 Jahren
Ursprung
Commit
e878df5eb1
1 geänderte Dateien mit 3 neuen und 0 gelöschten Zeilen
  1. 3 0
      src/core/network/socket.cpp

+ 3 - 0
src/core/network/socket.cpp

@@ -199,6 +199,9 @@ TCPSocket::TCPSocket(const TCPSocket &other)
 
 
 TCPSocket &TCPSocket::operator=(const TCPSocket &other)
 TCPSocket &TCPSocket::operator=(const TCPSocket &other)
 {
 {
+	if (CE_UNLIKELY(this == &other))
+		return *this;
+
 	_priv = new (_data) Private();
 	_priv = new (_data) Private();
 	memcpy(_data, other._data, sizeof(_data));
 	memcpy(_data, other._data, sizeof(_data));
 	return *this;
 	return *this;