Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect indentation in some multiline conditional compilation directives #7820

Open
gilles-peskine-arm opened this issue Jun 22, 2023 · 0 comments
Labels
bug component-test Test framework and CI scripts help-wanted This issue is not being actively worked on, but PRs welcome. priority-low Low priority - this may not receive review soon

Comments

@gilles-peskine-arm
Copy link
Contributor

The tool we use for code styling (uncrustify) has a bug that causes it to use misleading indentation in continuation lines for conditional compilation directives. For example:

#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED) && \
    (defined(MBEDTLS_SSL_RENEGOTIATION)              || \
    defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH))

We'd like defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH) to be left-aligned with defined(MBEDTLS_SSL_RENEGOTIATION) so that it's obvious to the reader that this is 1 && (2 || 3) and not (1 && 2) || 3. But that's not what we get from uncrustify.

This is just a code readability issue — it doesn't affect the behavior of the code, unless of course someone who edited it was mislead by the presentation.

You can use the following one-big-liner to look for problematic lines (many of them exhibit an instance of the bug):

perl -ne '/^ *# *(el)?if\b.*\\$/ or next; $_ .= <> while /\\$/; $x = $_; $x =~ tr/()\n//dc; 1 while $x =~ s/\(\)//g; $x =~ s/\n+\Z$//; print "\e[35m$ARGV:$.:\e[0m\n$_" if $x } continue { close ARGV if eof' $(git ls-files '**.c' '**.h' '**.function' ':!**/check_config.h')

This issue exists so that we can remember the readability issue if it comes up again in code reviews, and as a repository for any investigation we do towards a solution. Definition of done: we find a way to no longer have this misleading indentation, either by upgrading uncrustify if the bug gets fixed, or by tweaking the configuration if we find a workaround.

@gilles-peskine-arm gilles-peskine-arm added bug help-wanted This issue is not being actively worked on, but PRs welcome. component-test Test framework and CI scripts priority-low Low priority - this may not receive review soon labels Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug component-test Test framework and CI scripts help-wanted This issue is not being actively worked on, but PRs welcome. priority-low Low priority - this may not receive review soon
Projects
None yet
Development

No branches or pull requests

1 participant