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
125 stars 149 forks source link

Avoid compiler warnings about the printf formats in IPv6 modules #1119

Closed htibosch closed 3 months ago

htibosch commented 3 months ago

Description

As an option, the code in FreeRTOS+TCP can produce logging.

In three modules, my GNU compiler gives many warnings about the printf format used:

FreeRTOS_DHCPv6.c FreeRTOS_IPv6_Utils.c FreeRTOS_RA.c

For example in FreeRTOS_IPv6_Utils.c :

FreeRTOS_debug_printf( ( "%lu + %lu is larger than %lu\n",
                         uxIndex,
                         uxHopSize,
                         uxBufferLength ) );

gives 3 warnings of this type:

warning: format '%lu' expects argument of type 'long unsigned int',
but argument 3 has type 'size_t {aka unsigned int}' [-Wformat=]

In other modules, we solved this problem casting to either int or unsigned and using %u:

FreeRTOS_debug_printf( ( "%u + %u is larger than %u\n",
                         ( unsigned ) uxIndex,
                         ( unsigned ) uxHopSize,
                         ( unsigned ) uxBufferLength ) );

The logging is the same, and the warnings have gone, independent of the platform.

Earlier I wrote about my multi-platform testing of various printf formats.

Test Steps

Checklist:

Related Issue

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

htibosch commented 3 months ago

/bot run uncrustify