From 11773a3179b2d11b6f2ead9f116c3dc31c9f0055 Mon Sep 17 00:00:00 2001 From: w00384045 Date: Thu, 29 Jun 2017 19:43:53 +0800 Subject: [PATCH] avoid assignment to self --- handy/net.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handy/net.h b/handy/net.h index 2905db7..0e3c43e 100644 --- a/handy/net.h +++ b/handy/net.h @@ -55,7 +55,7 @@ struct Buffer { Buffer& absorb(Buffer& buf); void setSuggestSize(size_t sz) { exp_ = sz; } Buffer(const Buffer& b) { copyFrom(b); } - Buffer& operator=(const Buffer& b) { delete[] buf_; buf_ = NULL; copyFrom(b); return *this; } + Buffer& operator=(const Buffer& b) { if(this == &b) return *this; delete[] buf_; buf_ = NULL; copyFrom(b); return *this; } operator Slice () { return Slice(data(), size()); } private: char* buf_; @@ -65,4 +65,4 @@ struct Buffer { void copyFrom(const Buffer& b); }; -} \ No newline at end of file +}