From 82dbc8ec290a83bdd2fe3e638ff657873317be0b Mon Sep 17 00:00:00 2001 From: LiangKam Date: Wed, 21 Oct 2026 01:07:49 +0900 Subject: [PATCH] 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. --- scripts/check-unixnu.py | 7 +++++++ scripts/unixnu/config.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) mode change 100644 => 100755 scripts/check-unixnu.py diff --git a/scripts/check-unixnu.py b/scripts/check-unixnu.py old mode 100644 new mode 100755 index 181e592..d8942d9 --- a/scripts/check-unixnu.py +++ b/scripts/check-unixnu.py @@ -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') diff --git a/scripts/unixnu/config.py b/scripts/unixnu/config.py index b19320d..5e7f20a 100644 --- a/scripts/unixnu/config.py +++ b/scripts/unixnu/config.py @@ -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