/
githubmirror
/
bitcoin
Обзор
Документация
Войти
/
githubmirror
/
bitcoin
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/test/fuzz/locale.cpp
66 строк
12 KB
Hennadii Stepanov
fuzz, refactor: Remove unused `random_string` in `locale.cpp`
06 авг 2026, 14:21
Не верифицирован
06 авг 2026, 14:21
3df0d06
Код
Авторство
О чём код?
// Copyright (c) 2020-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <test/fuzz/FuzzedDataProvider.h> #include <test/fuzz/fuzz.h> #include <tinyformat.h> #include <util/strencodings.h> #include <util/string.h> #include <cassert> #include <clocale> #include <cstdint> #include <locale> #include <string> #include <vector> namespace { const std::string locale_identifiers[] = { "C", "C.UTF-8", "aa_DJ", "aa_DJ.ISO-8859-1", "aa_DJ.UTF-8", "aa_ER", "aa_ER.UTF-8", "aa_ET", "aa_ET.UTF-8", "af_ZA", "af_ZA.ISO-8859-1", "af_ZA.UTF-8", "agr_PE", "agr_PE.UTF-8", "ak_GH", "ak_GH.UT … [Строка слишком длинная. Вы можете скачать файл] std::string ConsumeLocaleIdentifier(FuzzedDataProvider& fuzzed_data_provider) { return fuzzed_data_provider.PickValueInArray<std::string>(locale_identifiers); } bool IsAvailableLocale(const std::string& locale_identifier) { try { (void)std::locale(locale_identifier); } catch (const std::runtime_error&) { return false; } return true; } } // namespace FUZZ_TARGET(locale) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); const std::string locale_identifier = ConsumeLocaleIdentifier(fuzzed_data_provider); if (!IsAvailableLocale(locale_identifier)) { return; } const char* c_locale = std::setlocale(LC_ALL, "C"); assert(c_locale != nullptr); const int64_t random_int64 = fuzzed_data_provider.ConsumeIntegral<int64_t>(); const std::string tostring_without_locale = util::ToString(random_int64); const std::string strprintf_int_without_locale = strprintf("%d", random_int64); const double random_double = fuzzed_data_provider.ConsumeFloatingPoint<double>(); const std::string strprintf_double_without_locale = strprintf("%f", random_double); const char* new_locale = std::setlocale(LC_ALL, locale_identifier.c_str()); assert(new_locale != nullptr); const std::string tostring_with_locale = util::ToString(random_int64); assert(tostring_without_locale == tostring_with_locale); const std::string strprintf_int_with_locale = strprintf("%d", random_int64); assert(strprintf_int_without_locale == strprintf_int_with_locale); const std::string strprintf_double_with_locale = strprintf("%f", random_double); assert(strprintf_double_without_locale == strprintf_double_with_locale); const std::locale current_cpp_locale; assert(current_cpp_locale == std::locale::classic()); }