diff --git a/native/cocos/2d/CCTextFieldTTF.cpp b/native/cocos/2d/CCTextFieldTTF.cpp index 59362951c3..d3a1177bfb 100644 --- a/native/cocos/2d/CCTextFieldTTF.cpp +++ b/native/cocos/2d/CCTextFieldTTF.cpp @@ -120,7 +120,7 @@ bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const Siz } bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const std::string& fontName, float fontSize) { - _placeHolder = std::string(placeholder); + _placeHolder = placeholder; setSystemFontName(fontName); setSystemFontSize(fontSize); Label::setTextColor(_colorSpaceHolder); diff --git a/native/cocos/base/ccUtils.cpp b/native/cocos/base/ccUtils.cpp index ec50c10356..4d3f858545 100644 --- a/native/cocos/base/ccUtils.cpp +++ b/native/cocos/base/ccUtils.cpp @@ -194,17 +194,25 @@ double atof(const char* str) return 0.0; } - char buf[MAX_ITOA_BUFFER_SIZE]; - strncpy(buf, str, MAX_ITOA_BUFFER_SIZE); - - // strip string, only remain 7 numbers after '.' - char* dot = strchr(buf, '.'); - if (dot != nullptr && dot - buf + 8 < MAX_ITOA_BUFFER_SIZE) + auto dot = strchr(str, '.'); + if (dot == nullptr) { - dot[8] = '\0'; + return std::atof(str); + } + else + { + char buf[MAX_ITOA_BUFFER_SIZE]; + strncpy(buf, str, MAX_ITOA_BUFFER_SIZE); + + // strip string, only remain 7 numbers after '.' + auto index = dot - str + 8; + if (index < MAX_ITOA_BUFFER_SIZE) + { + buf[index] = '\0'; + } + + return std::atof(buf); } - - return ::atof(buf); } double gettime() diff --git a/native/cocos/ui/UITextField.cpp b/native/cocos/ui/UITextField.cpp index e07d0d6265..d4d9d0d3ac 100644 --- a/native/cocos/ui/UITextField.cpp +++ b/native/cocos/ui/UITextField.cpp @@ -67,10 +67,10 @@ UICCTextField * UICCTextField::create(const std::string& placeholder, const std: void UICCTextField::onEnter() { + TextFieldTTF::onEnter(); TextFieldTTF::setDelegate(this); } - bool UICCTextField::onTextFieldAttachWithIME(TextFieldTTF *pSender) { setAttachWithIME(true); @@ -368,7 +368,7 @@ void TextField::onEnter() void TextField::initRenderer() { - _textFieldRenderer = UICCTextField::create("input words here", "Thonburi", 20); + _textFieldRenderer = UICCTextField::create("", "Thonburi", 20); addProtectedChild(_textFieldRenderer, TEXTFIELD_RENDERER_Z, -1); }