fix(config): parse zero-prefixed decimal values as base 10
The defconfig grammar accepts signed decimal digit sequences, but int(raw, 0) rejects nonzero decimal values with leading zeroes, such as 08, 010 and -08. Select base 16 only for the existing 0x form and base 10 otherwise, preserving signed hexadecimal values. Add 16 numeric regression cases to the build driver's existing self-test.
This commit is contained in:
1 parent
5d3cd768e0
commit
82dbc8ec29
2 files changed
+8
-1
No files matched your search
Regular → Executable
+7
@@ -50,6 +50,13 @@ def der(tag, body):
|
||||
def main():
|
||||
config = parse_config('# c\nCONFIG_A=y\nCONFIG_B=n\n# CONFIG_C is not set\nCONFIG_D="x y"\nCONFIG_E=0x10\n')
|
||||
expect(config == {'A': True, 'B': False, 'C': False, 'D': 'x y', 'E': 16}, 'defconfig values')
|
||||
for raw, value in (
|
||||
('0', 0), ('-0', 0), ('00', 0), ('-00', 0),
|
||||
('8', 8), ('-8', -8), ('08', 8), ('-08', -8),
|
||||
('010', 10), ('-010', -10), ('00042', 42), ('-00042', -42),
|
||||
('0x10', 16), ('-0x10', -16), ('0x00FF', 255), ('-0x00FF', -255),
|
||||
):
|
||||
expect(parse_config(f'CONFIG_NUMBER={raw}\n') == {'NUMBER': value}, f'defconfig number: {raw}')
|
||||
try:
|
||||
parse_config('CONFIG_A=maybe\n')
|
||||
expect(False, 'bad defconfig value accepted')
|
||||
|
||||
@@ -51,7 +51,7 @@ def parse_config(text):
|
||||
elif raw.startswith('"') and raw.endswith('"') and len(raw) >= 2:
|
||||
values[name] = raw[1:-1]
|
||||
elif re.fullmatch(r'-?(0x[0-9a-fA-F]+|\d+)', raw):
|
||||
values[name] = int(raw, 0)
|
||||
values[name] = int(raw, 16 if raw.lstrip('-').startswith('0x') else 10)
|
||||
else:
|
||||
raise Error(f'defconfig line {number}: value must be y, n, a number or a quoted string: {line}')
|
||||
return values
|
||||
|
||||
Reference in new issue
Block a user