- Timestamp:
- Jul 2, 2009 12:25:07 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/ministring_cpp.h
r21154 r21156 61 61 62 62 ministring(const ministring &s) 63 : m_psz(NULL)64 63 { 65 64 copyFrom(s); … … 67 66 68 67 ministring(const char *pcsz) 69 : m_psz(NULL)70 68 { 71 69 copyFrom(pcsz); … … 150 148 ministring& operator=(const char *pcsz) 151 149 { 152 cleanup(); 153 copyFrom(pcsz); 150 if (m_psz != pcsz) 151 { 152 cleanup(); 153 copyFrom(pcsz); 154 } 154 155 return *this; 155 156 } … … 157 158 ministring& operator=(const ministring &s) 158 159 { 159 cleanup(); 160 copyFrom(s); 160 if (this != &s) 161 { 162 cleanup(); 163 copyFrom(s); 164 } 161 165 return *this; 162 166 } … … 272 276 void copyFrom(const ministring &s) 273 277 { 274 if (&s != this) 275 { 276 m_cbLength = s.m_cbLength; 277 m_cbAllocated = m_cbLength + 1; 278 m_psz = (char*)RTMemAlloc(m_cbAllocated); 279 memcpy(m_psz, s.m_psz, m_cbAllocated); // include 0 terminator 280 } 278 m_cbLength = s.m_cbLength; 279 m_cbAllocated = m_cbLength + 1; 280 m_psz = (char*)RTMemAlloc(m_cbAllocated); 281 memcpy(m_psz, s.m_psz, m_cbAllocated); // include 0 terminator 281 282 } 282 283 … … 291 292 void copyFrom(const char *pcsz) 292 293 { 293 if (pcsz != m_psz) // leaves NULL as NULL also 294 { 295 if (pcsz) 296 { 297 m_cbLength = strlen(pcsz); 298 m_cbAllocated = m_cbLength + 1; 299 m_psz = (char*)RTMemAlloc(m_cbAllocated); 300 memcpy(m_psz, pcsz, m_cbAllocated); // include 0 terminator 301 } 302 else 303 { 304 m_cbLength = 0; 305 m_cbAllocated = 0; 306 m_psz = NULL; 307 } 294 if (pcsz) 295 { 296 m_cbLength = strlen(pcsz); 297 m_cbAllocated = m_cbLength + 1; 298 m_psz = (char*)RTMemAlloc(m_cbAllocated); 299 memcpy(m_psz, pcsz, m_cbAllocated); // include 0 terminator 300 } 301 else 302 { 303 m_cbLength = 0; 304 m_cbAllocated = 0; 305 m_psz = NULL; 308 306 } 309 307 }
Note:
See TracChangeset
for help on using the changeset viewer.