From c6b46474bfd7e803f36a8296f58c14ab4de9f903 Mon Sep 17 00:00:00 2001 From: minosgalanakis <30719586+minosgalanakis@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:00:56 +0100 Subject: [PATCH] c_wrapper_generator: Fixed an edge-case in strip_indentation(). Co-authored-by: Gilles Peskine Signed-off-by: minosgalanakis <30719586+minosgalanakis@users.noreply.github.com> --- scripts/mbedtls_framework/c_wrapper_generator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/mbedtls_framework/c_wrapper_generator.py b/scripts/mbedtls_framework/c_wrapper_generator.py index 25dc3f500..db62bdd14 100644 --- a/scripts/mbedtls_framework/c_wrapper_generator.py +++ b/scripts/mbedtls_framework/c_wrapper_generator.py @@ -44,9 +44,9 @@ def strip_indentation(in_str: str, new_lines: int = 1, indent_lv: int = 0) -> st # Count empty spaces in beggining of each line. The smallest non-zero entry # will be used to clean up input indentation. - _common_indents = min([len(n) for n in re.findall(r'(?m)^ +', in_str)]) - if _common_indents: - _ret_string = re.sub(r'(?m)^ {{{indent}}}'.format(indent=_common_indents), + indents = [len(n) for n in re.findall(r'(?m)^ +', in_str)] + if indents: + _ret_string = re.sub(r'(?m)^ {{{indent}}}'.format(indent=min(indents)), '', _ret_string) if indent_lv: _ret_string = '\n'.join([' ' * indent_lv * 4 + s