fix: silence -Wunsafe-buffer-usage warning in GetPreferredLanguages() (#44333)

fix: use UNSAFE_BUFFERS macro in GetPreferredLanguages()
This commit is contained in:
Charles Kerr 2024-10-21 18:20:00 -05:00 committed by GitHub
parent fff6ea438a
commit e3e94d45ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,7 +22,10 @@ std::vector<std::string> GetPreferredLanguages() {
DCHECK(languages); // A valid pointer is guaranteed.
DCHECK(*languages); // At least one entry, "C", is guaranteed.
for (; *languages; ++languages) {
// SAFETY: |g_get_language_names()| returns a glib-owned array
// of const C strings, terminated by an empty string.
// This loop is the correct way to walk through its return values.
for (; *languages; UNSAFE_BUFFERS(++languages)) {
if (strcmp(*languages, "C") != 0) {
preferredLanguages.push_back(base::i18n::GetCanonicalLocale(*languages));
}