From a54756bcfc7c622ebf854e881cdf04c1ba00ec3b Mon Sep 17 00:00:00 2001 From: wzl12356 Date: Tue, 15 Mar 2022 18:34:50 +0800 Subject: [PATCH] kafka: fix operator= --- src/protocol/KafkaDataTypes.h | 87 ++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/src/protocol/KafkaDataTypes.h b/src/protocol/KafkaDataTypes.h index df1e9802..1a1a38cc 100644 --- a/src/protocol/KafkaDataTypes.h +++ b/src/protocol/KafkaDataTypes.h @@ -107,11 +107,14 @@ public: KafkaList& operator= (const KafkaList& copy) { - this->~KafkaList(); - this->ref = copy.ref; - ++*this->ref; - this->t_list = copy.t_list; - this->curpos = copy.curpos; + if (this != ©) + { + this->~KafkaList(); + this->ref = copy.ref; + ++*this->ref; + this->t_list = copy.t_list; + this->curpos = copy.curpos; + } return *this; } @@ -227,10 +230,13 @@ public: KafkaMap& operator= (const KafkaMap& copy) { - this->~KafkaMap(); - this->ref = copy.ref; - ++*this->ref; - this->t_map = copy.t_map; + if (this != ©) + { + this->~KafkaMap(); + this->ref = copy.ref; + ++*this->ref; + this->t_map = copy.t_map; + } return *this; } @@ -621,10 +627,13 @@ public: KafkaConfig& operator= (const KafkaConfig& copy) { - this->~KafkaConfig(); - this->ptr = copy.ptr; - this->ref = copy.ref; - ++*this->ref; + if (this != ©) + { + this->~KafkaConfig(); + this->ptr = copy.ptr; + this->ref = copy.ref; + ++*this->ref; + } return *this; } @@ -724,10 +733,13 @@ public: KafkaRecord& operator= (KafkaRecord& copy) { - this->~KafkaRecord(); - this->ptr = copy.ptr; - this->ref = copy.ref; - ++*this->ref; + if (this != ©) + { + this->~KafkaRecord(); + this->ptr = copy.ptr; + this->ref = copy.ref; + ++*this->ref; + } return *this; } @@ -851,13 +863,16 @@ public: KafkaToppar& operator= (KafkaToppar& copy) { - this->~KafkaToppar(); - this->ptr = copy.ptr; - this->ref = copy.ref; - ++*this->ref; - this->curpos = copy.curpos; - this->startpos = copy.startpos; - this->endpos = copy.endpos; + if (this != ©) + { + this->~KafkaToppar(); + this->ptr = copy.ptr; + this->ref = copy.ref; + ++*this->ref; + this->curpos = copy.curpos; + this->startpos = copy.startpos; + this->endpos = copy.endpos; + } return *this; } @@ -1039,11 +1054,14 @@ public: KafkaBroker& operator= (const KafkaBroker& copy) { - this->~KafkaBroker(); - this->ptr = copy.ptr; - this->ref = copy.ref; - if (this->ref) - ++*this->ref; + if (this != ©) + { + this->~KafkaBroker(); + this->ptr = copy.ptr; + this->ref = copy.ref; + if (this->ref) + ++*this->ref; + } return *this; } @@ -1200,10 +1218,13 @@ public: KafkaMeta& operator= (KafkaMeta& copy) { - this->~KafkaMeta(); - this->ptr = copy.ptr; - this->ref = copy.ref; - ++*this->ref; + if (this != ©) + { + this->~KafkaMeta(); + this->ptr = copy.ptr; + this->ref = copy.ref; + ++*this->ref; + } return *this; }