From a6e9c083a1c577facf7933a43553133a1dad665e Mon Sep 17 00:00:00 2001 From: Valerio Setti Date: Fri, 4 Oct 2024 06:36:30 +0200 Subject: [PATCH] generate_test_code.py: add check for numerical format Do not allow values starting with a 0 because they can be either accidentally octal or accidentally decimal. Hex values are not affected by this change. Signed-off-by: Valerio Setti --- scripts/generate_test_code.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/generate_test_code.py b/scripts/generate_test_code.py index 996350c56..1cd8c3838 100755 --- a/scripts/generate_test_code.py +++ b/scripts/generate_test_code.py @@ -209,6 +209,10 @@ CONDITION_VALUE_REGEX = r'[\d|\w|\(][\s_\(\)0-9a-zA-Z\+\-\*\/]*' CONDITION_REGEX = r'({})(?:\s*({})\s*({}))?$'.format(C_IDENTIFIER_REGEX, CONDITION_OPERATOR_REGEX, CONDITION_VALUE_REGEX) +# Match numerical values that start with a 0 because they can be accidentally +# octal or accidentally decimal. Hexadecimal values starting with '0x' are +# valid of course. +INVALID_NUMBER_FORMAT_REGEX = r'(0[0-9]+)' TEST_FUNCTION_VALIDATION_REGEX = r'\s*void\s+(?P\w+)\s*\(' FUNCTION_ARG_LIST_END_REGEX = r'.*\)' EXIT_LABEL_REGEX = r'^exit:' @@ -407,6 +411,8 @@ def validate_dependency(dependency): :return: input dependency stripped of leading & trailing white spaces. """ dependency = dependency.strip() + if re.match(INVALID_NUMBER_FORMAT_REGEX, dependency, re.I): + raise GeneratorInputError('Invalid numerical format %s' % dependency) if not re.match(CONDITION_REGEX, dependency, re.I): raise GeneratorInputError('Invalid dependency %s' % dependency) return dependency