FreeRTOS / FreeRTOS-Plus-TCP

FreeRTOS-Plus-TCP library repository. +TCP files only. Submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
MIT License
152 stars 163 forks source link

Remove MISRA and compiler warnings from FreeRTOSIPConfigDefaults.h #1051

Closed htibosch closed 11 months ago

htibosch commented 11 months ago

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:

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

AniruddhaKanhere commented 11 months ago

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.

moninom1 commented 11 months ago

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

1049