fix: -Wunsafe-buffer-usage warning in HasWordCharacters() (#44133)

This commit is contained in:
Charles Kerr 2024-10-09 13:02:00 -05:00 committed by GitHub
parent dbbdf55493
commit 78fa477726
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,6 +15,7 @@
#include "base/containers/contains.h" #include "base/containers/contains.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/strings/utf_string_conversion_utils.h"
#include "base/task/single_thread_task_runner.h" #include "base/task/single_thread_task_runner.h"
#include "components/spellcheck/renderer/spellcheck_worditerator.h" #include "components/spellcheck/renderer/spellcheck_worditerator.h"
#include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/dictionary.h"
@ -29,12 +30,9 @@ namespace electron::api {
namespace { namespace {
bool HasWordCharacters(const std::u16string& text, int index) { bool HasWordCharacters(const std::u16string& text, size_t index) {
const char16_t* data = text.data(); base_icu::UChar32 code;
int length = text.length(); while (base::ReadUnicodeCharacter(text.c_str(), text.size(), &index, &code)) {
while (index < length) {
uint32_t code = 0;
U16_NEXT(data, index, length, code);
UErrorCode error = U_ZERO_ERROR; UErrorCode error = U_ZERO_ERROR;
if (uscript_getScript(code, &error) != USCRIPT_COMMON) if (uscript_getScript(code, &error) != USCRIPT_COMMON)
return true; return true;