From 21b5351c3721359dbd28937c95e75ba4b435f0b7 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Tue, 10 Jul 2018 14:16:08 +0200 Subject: Warn if int/hex 'default' is outside active 'range' Only out-of-range user values generated warnings before. The C tools warn for neither of them. --- kconfiglib.py | 22 +++++++++++++++++----- testsuite.py | 4 ++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index 19cb32f..881e64a 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -3272,11 +3272,14 @@ class Symbol(object): if use_defaults: # No user value or invalid user value. Look at defaults. - for val_expr, cond in self.defaults: + # Used to implement the warning below + has_default = False + + for val_sym, cond in self.defaults: if expr_value(cond): - self._write_to_conf = True + has_default = self._write_to_conf = True - val = val_expr.str_value + val = val_sym.str_value if _is_base_n(val, base): val_num = int(val, base) @@ -3302,15 +3305,24 @@ class Symbol(object): if self.orig_type == INT else \ hex(clamp) + if has_default: + num2str = str if base == 10 else hex + self.kconfig._warn( + "default value {} on {} clamped to {} due to " + "being outside the active range ([{}, {}])" + .format(val_num, _name_and_loc(self), + num2str(clamp), num2str(low), + num2str(high))) + elif self.orig_type == STRING: if vis and self.user_value is not None: # If the symbol is visible and has a user value, use that val = self.user_value else: # Otherwise, look at defaults - for val_expr, cond in self.defaults: + for val_sym, cond in self.defaults: if expr_value(cond): - val = val_expr.str_value + val = val_sym.str_value self._write_to_conf = True break diff --git a/testsuite.py b/testsuite.py index c18e69f..a8254ea 100644 --- a/testsuite.py +++ b/testsuite.py @@ -256,7 +256,7 @@ def run_selftests(): print("Testing expression evaluation") - c = Kconfig("Kconfiglib/tests/Keval") + c = Kconfig("Kconfiglib/tests/Keval", warn=False) def verify_eval(expr, val): res = c.eval_string(expr) @@ -1297,7 +1297,7 @@ g print("Testing hex/int ranges") - c = Kconfig("Kconfiglib/tests/Krange") + c = Kconfig("Kconfiglib/tests/Krange", warn=False) for sym_name in "HEX_NO_RANGE", "INT_NO_RANGE", "HEX_40", "INT_40": sym = c.syms[sym_name] -- cgit v1.2.3