Skip to content

Commit da9114f

Browse files
ckerryangannyx
authored andcommitted
fix: -Wunsafe-buffer-usage warning in HasWordCharacters() (electron#44133)
1 parent eff60f1 commit da9114f

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

shell/renderer/api/electron_api_spell_check_client.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "base/containers/contains.h"
1616
#include "base/logging.h"
1717
#include "base/numerics/safe_conversions.h"
18+
#include "base/strings/utf_string_conversion_utils.h"
1819
#include "base/task/single_thread_task_runner.h"
1920
#include "components/spellcheck/renderer/spellcheck_worditerator.h"
2021
#include "shell/common/gin_helper/dictionary.h"
@@ -29,12 +30,9 @@ namespace electron::api {
2930

3031
namespace {
3132

32-
bool HasWordCharacters(const std::u16string& text, int index) {
33-
const char16_t* data = text.data();
34-
int length = text.length();
35-
while (index < length) {
36-
uint32_t code = 0;
37-
U16_NEXT(data, index, length, code);
33+
bool HasWordCharacters(const std::u16string& text, size_t index) {
34+
base_icu::UChar32 code;
35+
while (base::ReadUnicodeCharacter(text.c_str(), text.size(), &index, &code)) {
3836
UErrorCode error = U_ZERO_ERROR;
3937
if (uscript_getScript(code, &error) != USCRIPT_COMMON)
4038
return true;

0 commit comments

Comments
 (0)