mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-28 15:02:47 +02:00
Merge bitcoin/bitcoin#32434: lint: Remove string exclusion from locale check
fa24fdcb7f
lint: Remove string exclusion from locale check (MarcoFalke) Pull request description: The exclusion isn't needed. In fact, it prevents detection of `"bla" + wrong()`. For example, the following is not detected: ```diff diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index 1c2951deee..c1209013e5 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -336,7 +336,8 @@ RPCHelpMan addmultisigaddress() RPCHelpMan keypoolrefill() { return RPCHelpMan{"keypoolrefill", - "\nFills the keypool."+ + "\nRefills each descriptor keypool in the wallet up to the specified number of new keys.\n" + "By default, descriptor wallets have 4 active ranged descriptors (\"legacy\", \"p2sh-segwit\", \"bech32\", and \"bech32m\"), each with " + std::to_string(DEFAULT_KEYPOOL_SIZE) + " entries.\n" + HELP_REQUIRING_PASSPHRASE, { {"newsize", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%u, or as set by -keypool", DEFAULT_KEYPOOL_SIZE)}, "The new keypool size"}, ``` Fix the script by detecting it. ACKs for top commit: laanwj: Code review ACKfa24fdcb7f
. rkrux: ACKfa24fdcb7f
w0xlt: ACKfa24fdcb7f
Tree-SHA512: cb7e6ed9fec5d2089e94031329ebf26b83a1814ffbbbca94f7527c127bc759d13c0f4ea79b71ff7f5f009d071dcf01958c8921163d6dc5e1ae6256cc40b57eea
This commit is contained in:
@@ -1013,34 +1013,6 @@ Strings and formatting
|
||||
|
||||
- *Rationale*: These functions do overflow checking and avoid pesky locale issues.
|
||||
|
||||
- Avoid using locale dependent functions if possible. You can use the provided
|
||||
[`lint-locale-dependence.py`](/test/lint/lint-locale-dependence.py)
|
||||
to check for accidental use of locale dependent functions.
|
||||
|
||||
- *Rationale*: Unnecessary locale dependence can cause bugs that are very tricky to isolate and fix.
|
||||
|
||||
- These functions are known to be locale dependent:
|
||||
`alphasort`, `asctime`, `asprintf`, `atof`, `atoi`, `atol`, `atoll`, `atoq`,
|
||||
`btowc`, `ctime`, `dprintf`, `fgetwc`, `fgetws`, `fprintf`, `fputwc`,
|
||||
`fputws`, `fscanf`, `fwprintf`, `getdate`, `getwc`, `getwchar`, `isalnum`,
|
||||
`isalpha`, `isblank`, `iscntrl`, `isdigit`, `isgraph`, `islower`, `isprint`,
|
||||
`ispunct`, `isspace`, `isupper`, `iswalnum`, `iswalpha`, `iswblank`,
|
||||
`iswcntrl`, `iswctype`, `iswdigit`, `iswgraph`, `iswlower`, `iswprint`,
|
||||
`iswpunct`, `iswspace`, `iswupper`, `iswxdigit`, `isxdigit`, `mblen`,
|
||||
`mbrlen`, `mbrtowc`, `mbsinit`, `mbsnrtowcs`, `mbsrtowcs`, `mbstowcs`,
|
||||
`mbtowc`, `mktime`, `putwc`, `putwchar`, `scanf`, `snprintf`, `sprintf`,
|
||||
`sscanf`, `stoi`, `stol`, `stoll`, `strcasecmp`, `strcasestr`, `strcoll`,
|
||||
`strfmon`, `strftime`, `strncasecmp`, `strptime`, `strtod`, `strtof`,
|
||||
`strtoimax`, `strtol`, `strtold`, `strtoll`, `strtoq`, `strtoul`,
|
||||
`strtoull`, `strtoumax`, `strtouq`, `strxfrm`, `swprintf`, `tolower`,
|
||||
`toupper`, `towctrans`, `towlower`, `towupper`, `ungetwc`, `vasprintf`,
|
||||
`vdprintf`, `versionsort`, `vfprintf`, `vfscanf`, `vfwprintf`, `vprintf`,
|
||||
`vscanf`, `vsnprintf`, `vsprintf`, `vsscanf`, `vswprintf`, `vwprintf`,
|
||||
`wcrtomb`, `wcscasecmp`, `wcscoll`, `wcsftime`, `wcsncasecmp`, `wcsnrtombs`,
|
||||
`wcsrtombs`, `wcstod`, `wcstof`, `wcstoimax`, `wcstol`, `wcstold`,
|
||||
`wcstoll`, `wcstombs`, `wcstoul`, `wcstoull`, `wcstoumax`, `wcswidth`,
|
||||
`wcsxfrm`, `wctob`, `wctomb`, `wctrans`, `wctype`, `wcwidth`, `wprintf`
|
||||
|
||||
- For `strprintf`, `LogInfo`, `LogDebug`, etc formatting characters don't need size specifiers.
|
||||
|
||||
- *Rationale*: Bitcoin Core uses tinyformat, which is type safe. Leave them out to avoid confusion.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2018-2022 The Bitcoin Core developers
|
||||
# Copyright (c) 2018-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.
|
||||
#
|
||||
@@ -43,6 +43,7 @@ from subprocess import check_output, CalledProcessError
|
||||
|
||||
KNOWN_VIOLATIONS = [
|
||||
"src/dbwrapper.cpp:.*vsnprintf",
|
||||
"src/span.h:.*printf",
|
||||
"src/test/fuzz/locale.cpp:.*setlocale",
|
||||
"src/test/util_tests.cpp:.*strtoll",
|
||||
"src/util/syserror.cpp:.*strerror", # Outside this function use `SysErrorString`
|
||||
@@ -214,7 +215,7 @@ LOCALE_DEPENDENT_FUNCTIONS = [
|
||||
def find_locale_dependent_function_uses():
|
||||
regexp_locale_dependent_functions = "|".join(LOCALE_DEPENDENT_FUNCTIONS)
|
||||
exclude_args = [":(exclude)" + excl for excl in REGEXP_EXTERNAL_DEPENDENCIES_EXCLUSIONS]
|
||||
git_grep_command = ["git", "grep", "-E", "[^a-zA-Z0-9_\\`'\"<>](" + regexp_locale_dependent_functions + ")(_r|_s)?[^a-zA-Z0-9_\\`'\"<>]", "--", "*.cpp", "*.h"] + exclude_args
|
||||
git_grep_command = ["git", "grep", "--extended-regexp", "[^a-zA-Z0-9_\\`'\"<>](" + regexp_locale_dependent_functions + ")(_r|_s)?\\(", "--", "*.cpp", "*.h"] + exclude_args
|
||||
git_grep_output = list()
|
||||
|
||||
try:
|
||||
@@ -234,8 +235,8 @@ def main():
|
||||
|
||||
for locale_dependent_function in LOCALE_DEPENDENT_FUNCTIONS:
|
||||
matches = [line for line in git_grep_output
|
||||
if re.search("[^a-zA-Z0-9_\\`'\"<>]" + locale_dependent_function + "(_r|_s)?[^a-zA-Z0-9_\\`'\"<>]", line)
|
||||
and not re.search("\\.(c|cpp|h):\\s*(//|\\*|/\\*|\").*" + locale_dependent_function, line)
|
||||
if re.search("[^a-zA-Z0-9_\\`'\"<>]" + locale_dependent_function + "(_r|_s)?\\(", line)
|
||||
and not re.search("\\.(c|cpp|h):\\s*//.*" + locale_dependent_function, line)
|
||||
and not re.search(regexp_ignore_known_violations, line)]
|
||||
if matches:
|
||||
print(f"The locale dependent function {locale_dependent_function}(...) appears to be used:")
|
||||
|
Reference in New Issue
Block a user