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

Ensure that only one definition of ASSERT is present #3557

Merged
merged 1 commit into from
Aug 14, 2020

Conversation

Ouss4
Copy link
Contributor

@Ouss4 Ouss4 commented Aug 11, 2020

Description

If a previous definition of ASSERT has sneaked in through included files an "ASSERT redefined" warnings would show up.

Status

READY

Steps to test or reproduce

Build with MBEDTLS_SELF_TEST enabled.

@gilles-peskine-arm gilles-peskine-arm self-assigned this Aug 12, 2020
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch is harmless except for the small maintenance burden, so we'll probably accept it if you really need it. But the fact that you need this patch indicates that something is wrong in your platform headers. What platform is this? How is ASSERT getting defined?

Having one identifier #undef'ed is ok, but we wouldn't want to have #undef for every single identifier that a platform header might possibly define when it shouldn't.

Comment on lines 520 to 522
#ifdef ASSERT
#undef ASSERT
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the C standard, #undef ASSERT is enough: it simply has no effect if ASSERT isn't a defined macro. Are there compilers that warn about #undefining a macro that isn't defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, #undef only is enough.

@@ -516,6 +516,11 @@ static const size_t test_lengths[2] =
375U
};

/* Make sure no other definition is already present. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A conforming C implementation isn't allowed to define ASSERT: it's in the application namespace.

In this C file, we only include a few standard library headers, some headers of our own, config.h, and possibly platform_alt.h. Where is ASSERT coming from on your build? None of them should define ASSERT, but I realize that some embedded platforms define macros with “convenient” names that are officially reserved for applications.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it from other libraries I have with the project. I understand that these macros are only used for testing and maybe you don't want to #undef every macro.
It's just common to #undef common macros before defining them to avoid warnings. I'm okay with it if we drop this patch.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a changelog entry file in ChangeLog.d, something like

Changes
   * Undefine the ASSERT macro before defining it locally, in case it is defined
     in a platform header. Contributed by Abdelatif Guettouche in #3557.

@Ouss4 Ouss4 force-pushed the assert branch 2 times, most recently from 507f4b5 to e0b2687 Compare August 12, 2020 18:05
@Ouss4
Copy link
Contributor Author

Ouss4 commented Aug 12, 2020

Please add a changelog entry file in ChangeLog.d, something like

Changes
   * Undefine the ASSERT macro before defining it locally, in case it is defined
     in a platform header. Contributed by Abdelatif Guettouche in #3557.

Thanks for the text, I added an entry.

has sneaked in through included files.

Signed-off-by: Ouss4 <abdelatif.guettouche@gmail.com>
@danh-arm danh-arm added this to To do in Mbed TLS PRs via automation Aug 13, 2020
Mbed TLS PRs automation moved this from To do to Approved Aug 14, 2020
Copy link

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gilles-peskine-arm gilles-peskine-arm merged commit c60c30e into Mbed-TLS:development Aug 14, 2020
Mbed TLS PRs automation moved this from Approved to Done Aug 14, 2020
@Ouss4 Ouss4 deleted the assert branch August 15, 2020 07:52
@mpg
Copy link
Contributor

mpg commented Aug 20, 2020

@gilles-peskine-arm @hanno-arm I just noticed that the file with the ChangeLog entry got created in the wrong directory, so I made a trivial PR to fix this: #3584

@daverodgman daverodgman removed this from Done in Mbed TLS PRs Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-platform Portability layer and build scripts enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants