diff options
author | marina <marina@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-03-19 00:56:29 +0000 |
---|---|---|
committer | marina <marina@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-03-19 00:56:29 +0000 |
commit | c46eadfd8072ee04622f534b5ae52983b0b4e171 (patch) | |
tree | 1168fbe24e55dc10bd2e411cc2061a54d9fed94f /ace/SString.i | |
parent | fa41e43786598bc3e735d1a8a758e667fbdb69d3 (diff) | |
download | ATCD-c46eadfd8072ee04622f534b5ae52983b0b4e171.tar.gz |
fixed compare function, added some comments
Diffstat (limited to 'ace/SString.i')
-rw-r--r-- | ace/SString.i | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/ace/SString.i b/ace/SString.i index 09800bcc3c1..46b33d7541d 100644 --- a/ace/SString.i +++ b/ace/SString.i @@ -14,9 +14,6 @@ ACE_CString::ACE_CString (ACE_Allocator *alloc) release_ (0) { ACE_TRACE ("ACE_CString::ACE_CString"); - - //@@ Is this needed here? - this->set (0, 0, 0); } // Constructor that actually copies memory. @@ -238,8 +235,25 @@ ACE_CString::compare (const ACE_CString &s) const { ACE_TRACE ("ACE_CString::compare"); - // @@Is this correct? (i.e. for the case when they are of unequal length) - return ACE_OS::strncmp (this->rep_, s.rep_, this->len_); + // We can't just pass both strings to strcmp, since they are not + // guaranteed to be null-terminated. + + // Pick smaller of the two lengths and perform the comparison. + int smaller_length = (this->len_ < s.len_) ? this->len_ : s.len_; + int result = ACE_OS::strncmp (this->rep_, + s.rep_, + smaller_length); + + if (result != 0 || s.len_ == this->len_) + return result; + + else + // we need to differentiate based on length + if (this->len_ > s.len_) + return (this->rep_[smaller_length] - '\0'); + + else + return ('\0' - s.rep_[smaller_length]); } ACE_INLINE int |