Skip to content

Conversation

@htibosch
Copy link
Contributor

@htibosch htibosch commented Dec 1, 2023

Description

The changes made to FreeRTOSIPConfigDefaults.h in PR #782 were very good and useful, but they may trigger an important compiler warning:

warning: suggest braces around empty body in an 'if' statement [-Wempty-body]

In other words: it may hide the next statement when configPRINTF is defined as empty:

#ifndef FreeRTOS_printf
    #ifdef configPRINTF
        #define FreeRTOS_printf( MSG )    if( ipconfigHAS_PRINTF ) configPRINTF( MSG )
    #else
        #define FreeRTOS_printf( MSG )    do {} while( ipFALSE_BOOL )
    #endif
#endif

And also MISRA would get upset about the if statement condition which is always true/false in

if( ipconfigHAS_PRINTF ) configPRINTF( MSG )

I would like to replace it with this:

#ifndef FreeRTOS_printf
    #if ( ipconfigHAS_PRINTF == 1 ) && defined( configPRINTF )
        #define FreeRTOS_printf( MSG )    do { configPRINTF( MSG ); } while( ipFALSE_BOOL )
    #else
        #define FreeRTOS_printf( MSG )    do {} while( ipFALSE_BOOL )
    #endif
#endif

#ifndef FreeRTOS_debug_printf
    #if ( ipconfigHAS_DEBUG_PRINTF == 1 ) && defined( configPRINTF )
        #define FreeRTOS_debug_printf( MSG )    do { configPRINTF( MSG ); } while( ipFALSE_BOOL )
    #else
        #define FreeRTOS_debug_printf( MSG )    do {} while( ipFALSE_BOOL )
    #endif
#endif

Test Steps

Define ipconfigHAS_PRINTF=1 without defining FreeRTOS_printf() and run the compiler.
Or define ipconfigHAS_DEBUG_PRINTF=1 without defining FreeRTOS_debug_printf().
Also interesting is to try this with an empty configPRINTF() in your FreeRTOSConfig.h.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@htibosch htibosch requested a review from a team as a code owner December 1, 2023 08:18
@AniruddhaKanhere
Copy link
Member

The links seem to be accessible. Not sure why the link verifier is failing. Maybe a change in GitHub runners to not allow them to reach gnu.org?

Similarly, for the proof-ci, not sure why this simple change will cause 4 CBMC proofs to fail.

@htibosch htibosch mentioned this pull request Dec 5, 2023
2 tasks
@moninom1
Copy link
Member

moninom1 commented Dec 7, 2023

Closing this PR as the changes are taken as a part of Fix MISRA issue
#1049

@moninom1 moninom1 closed this Dec 7, 2023
@htibosch htibosch deleted the Remove_warnings_from_FreeRTOSIPConfigDefaults branch September 17, 2025 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants