From 39f98b5da9ebb0eea222040b8d2df0c0cecfc25e Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Wed, 2 Apr 2014 09:08:42 -0400
Subject: [PATCH] Encoding: Add self-assignment check to CommandLineArguments

This was caught by the HP compiler warning:

 warning #4285-D: operator= does not have a check for the source and
 destination addresses being non-identical

Change-Id: I074a33410402b2b872dee03df3d4006ffe32f111
---
 EncodingCXX.cxx | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/EncodingCXX.cxx b/EncodingCXX.cxx
index f76deb5..251a56d 100644
--- a/EncodingCXX.cxx
+++ b/EncodingCXX.cxx
@@ -110,16 +110,19 @@ Encoding::CommandLineArguments::
 Encoding::CommandLineArguments&
 Encoding::CommandLineArguments::operator=(const CommandLineArguments& other)
 {
-  size_t i;
-  for(i=0; i<this->argv_.size(); i++)
+  if(this != &other)
     {
-    free(this->argv_[i]);
-    }
+    size_t i;
+    for(i=0; i<this->argv_.size(); i++)
+      {
+      free(this->argv_[i]);
+      }
 
-  this->argv_.resize(other.argv_.size());
-  for(i=0; i<this->argv_.size(); i++)
-    {
-    this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : 0;
+    this->argv_.resize(other.argv_.size());
+    for(i=0; i<this->argv_.size(); i++)
+      {
+      this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : 0;
+      }
     }
 
   return *this;
-- 
GitLab