diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-07-10 14:16:08 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-07-10 14:19:04 +0200 |
| commit | 21b5351c3721359dbd28937c95e75ba4b435f0b7 (patch) | |
| tree | 1181c464c90bfde779e57c149cb455ad6ae7bdaa | |
| parent | 652d9916b12e1b2ee918b61d04ff23226d2fa4cd (diff) | |
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.
| -rw-r--r-- | kconfiglib.py | 22 | ||||
| -rw-r--r-- | 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] |
