Skip to content

Commit 6469752

Browse files
committed
Merge bitcoin/bitcoin#32434: lint: Remove string exclusion from locale check
fa24fdc 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 1c2951d..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 ACK fa24fdc. rkrux: ACK fa24fdc w0xlt: ACK bitcoin/bitcoin@fa24fdc Tree-SHA512: cb7e6ed9fec5d2089e94031329ebf26b83a1814ffbbbca94f7527c127bc759d13c0f4ea79b71ff7f5f009d071dcf01958c8921163d6dc5e1ae6256cc40b57eea
2 parents 03ebdd0 + fa24fdc commit 6469752

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

doc/developer-notes.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,34 +1013,6 @@ Strings and formatting
10131013
10141014
- *Rationale*: These functions do overflow checking and avoid pesky locale issues.
10151015
1016-
- Avoid using locale dependent functions if possible. You can use the provided
1017-
[`lint-locale-dependence.py`](/test/lint/lint-locale-dependence.py)
1018-
to check for accidental use of locale dependent functions.
1019-
1020-
- *Rationale*: Unnecessary locale dependence can cause bugs that are very tricky to isolate and fix.
1021-
1022-
- These functions are known to be locale dependent:
1023-
`alphasort`, `asctime`, `asprintf`, `atof`, `atoi`, `atol`, `atoll`, `atoq`,
1024-
`btowc`, `ctime`, `dprintf`, `fgetwc`, `fgetws`, `fprintf`, `fputwc`,
1025-
`fputws`, `fscanf`, `fwprintf`, `getdate`, `getwc`, `getwchar`, `isalnum`,
1026-
`isalpha`, `isblank`, `iscntrl`, `isdigit`, `isgraph`, `islower`, `isprint`,
1027-
`ispunct`, `isspace`, `isupper`, `iswalnum`, `iswalpha`, `iswblank`,
1028-
`iswcntrl`, `iswctype`, `iswdigit`, `iswgraph`, `iswlower`, `iswprint`,
1029-
`iswpunct`, `iswspace`, `iswupper`, `iswxdigit`, `isxdigit`, `mblen`,
1030-
`mbrlen`, `mbrtowc`, `mbsinit`, `mbsnrtowcs`, `mbsrtowcs`, `mbstowcs`,
1031-
`mbtowc`, `mktime`, `putwc`, `putwchar`, `scanf`, `snprintf`, `sprintf`,
1032-
`sscanf`, `stoi`, `stol`, `stoll`, `strcasecmp`, `strcasestr`, `strcoll`,
1033-
`strfmon`, `strftime`, `strncasecmp`, `strptime`, `strtod`, `strtof`,
1034-
`strtoimax`, `strtol`, `strtold`, `strtoll`, `strtoq`, `strtoul`,
1035-
`strtoull`, `strtoumax`, `strtouq`, `strxfrm`, `swprintf`, `tolower`,
1036-
`toupper`, `towctrans`, `towlower`, `towupper`, `ungetwc`, `vasprintf`,
1037-
`vdprintf`, `versionsort`, `vfprintf`, `vfscanf`, `vfwprintf`, `vprintf`,
1038-
`vscanf`, `vsnprintf`, `vsprintf`, `vsscanf`, `vswprintf`, `vwprintf`,
1039-
`wcrtomb`, `wcscasecmp`, `wcscoll`, `wcsftime`, `wcsncasecmp`, `wcsnrtombs`,
1040-
`wcsrtombs`, `wcstod`, `wcstof`, `wcstoimax`, `wcstol`, `wcstold`,
1041-
`wcstoll`, `wcstombs`, `wcstoul`, `wcstoull`, `wcstoumax`, `wcswidth`,
1042-
`wcsxfrm`, `wctob`, `wctomb`, `wctrans`, `wctype`, `wcwidth`, `wprintf`
1043-
10441016
- For `strprintf`, `LogInfo`, `LogDebug`, etc formatting characters don't need size specifiers.
10451017
10461018
- *Rationale*: Bitcoin Core uses tinyformat, which is type safe. Leave them out to avoid confusion.

test/lint/lint-locale-dependence.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2018-2022 The Bitcoin Core developers
2+
# Copyright (c) 2018-present The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
#
@@ -43,6 +43,7 @@
4343

4444
KNOWN_VIOLATIONS = [
4545
"src/dbwrapper.cpp:.*vsnprintf",
46+
"src/span.h:.*printf",
4647
"src/test/fuzz/locale.cpp:.*setlocale",
4748
"src/test/util_tests.cpp:.*strtoll",
4849
"src/util/syserror.cpp:.*strerror", # Outside this function use `SysErrorString`
@@ -214,7 +215,7 @@
214215
def find_locale_dependent_function_uses():
215216
regexp_locale_dependent_functions = "|".join(LOCALE_DEPENDENT_FUNCTIONS)
216217
exclude_args = [":(exclude)" + excl for excl in REGEXP_EXTERNAL_DEPENDENCIES_EXCLUSIONS]
217-
git_grep_command = ["git", "grep", "-E", "[^a-zA-Z0-9_\\`'\"<>](" + regexp_locale_dependent_functions + ")(_r|_s)?[^a-zA-Z0-9_\\`'\"<>]", "--", "*.cpp", "*.h"] + exclude_args
218+
git_grep_command = ["git", "grep", "--extended-regexp", "[^a-zA-Z0-9_\\`'\"<>](" + regexp_locale_dependent_functions + ")(_r|_s)?\\(", "--", "*.cpp", "*.h"] + exclude_args
218219
git_grep_output = list()
219220

220221
try:
@@ -234,8 +235,8 @@ def main():
234235

235236
for locale_dependent_function in LOCALE_DEPENDENT_FUNCTIONS:
236237
matches = [line for line in git_grep_output
237-
if re.search("[^a-zA-Z0-9_\\`'\"<>]" + locale_dependent_function + "(_r|_s)?[^a-zA-Z0-9_\\`'\"<>]", line)
238-
and not re.search("\\.(c|cpp|h):\\s*(//|\\*|/\\*|\").*" + locale_dependent_function, line)
238+
if re.search("[^a-zA-Z0-9_\\`'\"<>]" + locale_dependent_function + "(_r|_s)?\\(", line)
239+
and not re.search("\\.(c|cpp|h):\\s*//.*" + locale_dependent_function, line)
239240
and not re.search(regexp_ignore_known_violations, line)]
240241
if matches:
241242
print(f"The locale dependent function {locale_dependent_function}(...) appears to be used:")

0 commit comments

Comments
 (0)