Author: wyoung
Date: Wed Jul 11 23:27:51 2007
New Revision: 1666
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1666&view=rev
Log:
One last change to const_string: now handling C and C++ strings the same
way: adding a null character to the allocated array, but not counting it
against the length. The previous version would include the null in the
copy from const_string to C++ string due to this error.
Modified:
trunk/lib/const_string.h
Modified: trunk/lib/const_string.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/const_string.h?rev=1666&r1=1665&r2=1666&view=diff
==============================================================================
--- trunk/lib/const_string.h (original)
+++ trunk/lib/const_string.h Wed Jul 11 23:27:51 2007
@@ -95,19 +95,21 @@
/// \brief Initialize string from existing C string
const_string(const char* str) :
str_data_(0),
- length_(size_type(strlen(str) + 1))
- {
- str_data_ = new char[length_];
+ length_(size_type(strlen(str)))
+ {
+ str_data_ = new char[length_ + 1];
memcpy(str_data_, str, length_);
+ str_data_[length_] = '\0';
}
/// \brief Initialize string from existing C string of known length
const_string(const char* str, size_type len) :
str_data_(0),
- length_(size_type(len + 1))
- {
- str_data_ = new char[length_];
+ length_(size_type(len))
+ {
+ str_data_ = new char[length_ + 1];
memcpy(str_data_, str, length_);
+ str_data_[length_] = '\0';
}
/// \brief Destroy string
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits