1
0
Fork 0

fixed crash

This commit is contained in:
Jan Steemann 2016-04-21 18:04:10 +02:00
parent 2f72be9041
commit 7f30e30c1d
1 changed files with 24 additions and 13 deletions

View File

@ -425,44 +425,55 @@ static int write32(int fd, char32_t* text32, int len32) {
class Utf32String {
public:
Utf32String() : _length(0) { _data = new char32_t[1](); }
Utf32String() : _length(0), _data(nullptr) {
// note: parens intentional, _data must be properly initialized
_data = new char32_t[1]();
}
explicit Utf32String(const char* src) {
explicit Utf32String(const char* src) : _length(0), _data(nullptr) {
size_t len = strlen(src);
_data = new char32_t[len + 1];
// note: parens intentional, _data must be properly initialized
_data = new char32_t[len + 1]();
copyString8to32(_data, len + 1, _length, src);
}
explicit Utf32String(const char8_t* src) {
explicit Utf32String(const char8_t* src) : _length(0), _data(nullptr) {
size_t len = strlen(reinterpret_cast<const char*>(src));
_data = new char32_t[len + 1];
// note: parens intentional, _data must be properly initialized
_data = new char32_t[len + 1]();
copyString8to32(_data, len + 1, _length, src);
}
explicit Utf32String(const char32_t* src) {
explicit Utf32String(const char32_t* src) : _length(0), _data(nullptr) {
for (_length = 0; src[_length] != 0; ++_length) {
}
_data = new char32_t[_length + 1];
// note: parens intentional, _data must be properly initialized
_data = new char32_t[_length + 1]();
memcpy(_data, src, _length * sizeof(char32_t));
}
explicit Utf32String(const char32_t* src, int len) : _length(len) {
_data = new char32_t[len + 1];
explicit Utf32String(const char32_t* src, int len) : _length(len), _data(nullptr) {
// note: parens intentional, _data must be properly initialized
_data = new char32_t[len + 1]();
memcpy(_data, src, len * sizeof(char32_t));
}
explicit Utf32String(int len) : _length(0) { _data = new char32_t[len]; }
explicit Utf32String(int len) : _length(0), _data(nullptr) {
// note: parens intentional, _data must be properly initialized
_data = new char32_t[len]();
}
explicit Utf32String(const Utf32String& that) : _length(that._length) {
_data = new char32_t[_length + 1];
explicit Utf32String(const Utf32String& that) : _length(that._length), _data(nullptr) {
// note: parens intentional, _data must be properly initialized
_data = new char32_t[_length + 1]();
memcpy(_data, that._data, sizeof(char32_t) * _length);
}
Utf32String& operator=(const Utf32String& that) {
if (this != &that) {
delete[] _data;
_data = new char32_t[that._length];
_data = new char32_t[that._length]();
_length = that._length;
memcpy(_data, that._data, sizeof(char32_t) * _length);
}