aboutsummaryrefslogtreecommitdiff
path: root/test/lint
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-05-26 13:18:18 +0100
committerfanquake <fanquake@gmail.com>2023-05-26 13:33:42 +0100
commit66b08e78226059e2d31450aadc2423d77003eaf1 (patch)
tree9c1a677f699072a99876311cb93d65413f6c978e /test/lint
parent4d13fe47be175d01a59147e514da554a88028e10 (diff)
parenteefe56967b4eb4b5144325cde4f40fc1cbde3e65 (diff)
downloadbitcoin-66b08e78226059e2d31450aadc2423d77003eaf1.tar.xz
Merge bitcoin/bitcoin#27302: init: Error if ignored bitcoin.conf file is found
eefe56967b4eb4b5144325cde4f40fc1cbde3e65 bugfix: Fix incorrect debug.log config file path (Ryan Ofsky) 3746f00be1b732a04976fc70cbb0661f97bbbd99 init: Error if ignored bitcoin.conf file is found (Ryan Ofsky) 398c3719b02197ad92fded20f6ff83b364747297 lint: Fix lint-format-strings false positives when format specifiers have argument positions (Ryan Ofsky) Pull request description: Show an error on startup if a bitcoin datadir that is being used contains a `bitcoin.conf` file that is ignored. There are two cases where this could happen: - One case reported in [#27246 (comment)](https://github.com/bitcoin/bitcoin/issues/27246#issuecomment-1470006043) happens when a `bitcoin.conf` file in the default datadir (e.g. `$HOME/.bitcoin/bitcoin.conf`) has a `datadir=/path` line that sets different datadir containing a second `bitcoin.conf` file. Currently the second `bitcoin.conf` file is ignored with no warning. - Another way this could happen is if a `-conf=` command line argument points to a configuration file with a `datadir=/path` line and that path contains a `bitcoin.conf` file, which is currently ignored. This change only adds an error message and doesn't change anything about way settings are applied. It also doesn't trigger errors if there are redundant `-datadir` or `-conf` settings pointing at the same configuration file, only if they are pointing at different files and one file is being ignored. ACKs for top commit: pinheadmz: re-ACK eefe56967b4eb4b5144325cde4f40fc1cbde3e65 willcl-ark: re-ACK eefe56967b TheCharlatan: ACK eefe56967b4eb4b5144325cde4f40fc1cbde3e65 Tree-SHA512: 939a98a4b271b5263d64a2df3054c56fcde94784edf6f010d78693a371c38aa03138ae9cebb026b6164bbd898d8fd0845a61a454fd996e328fd7bcf51c580c2b
Diffstat (limited to 'test/lint')
-rwxr-xr-xtest/lint/run-lint-format-strings.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/test/lint/run-lint-format-strings.py b/test/lint/run-lint-format-strings.py
index 91915f05f9..d1896dba84 100755
--- a/test/lint/run-lint-format-strings.py
+++ b/test/lint/run-lint-format-strings.py
@@ -241,20 +241,32 @@ def count_format_specifiers(format_string):
3
>>> count_format_specifiers("foo %d bar %i foo %% foo %*d foo")
4
+ >>> count_format_specifiers("foo %5$d")
+ 5
+ >>> count_format_specifiers("foo %5$*7$d")
+ 7
"""
assert type(format_string) is str
format_string = format_string.replace('%%', 'X')
- n = 0
- in_specifier = False
- for i, char in enumerate(format_string):
- if char == "%":
- in_specifier = True
+ n = max_pos = 0
+ for m in re.finditer("%(.*?)[aAcdeEfFgGinopsuxX]", format_string, re.DOTALL):
+ # Increase the max position if the argument has a position number like
+ # "5$", otherwise increment the argument count.
+ pos_num, = re.match(r"(?:(^\d+)\$)?", m.group(1)).groups()
+ if pos_num is not None:
+ max_pos = max(max_pos, int(pos_num))
+ else:
n += 1
- elif char in "aAcdeEfFgGinopsuxX":
- in_specifier = False
- elif in_specifier and char == "*":
+
+ # Increase the max position if there is a "*" width argument with a
+ # position like "*7$", and increment the argument count if there is a
+ # "*" width argument with no position.
+ star, star_pos_num = re.match(r"(?:.*?(\*(?:(\d+)\$)?)|)", m.group(1)).groups()
+ if star_pos_num is not None:
+ max_pos = max(max_pos, int(star_pos_num))
+ elif star is not None:
n += 1
- return n
+ return max(n, max_pos)
def main():