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

Fix printf warnings #1222

Merged
merged 3 commits into from
Feb 3, 2025
Merged

Fix printf warnings #1222

merged 3 commits into from
Feb 3, 2025

Conversation

concatime
Copy link
Contributor

Handle correctly types when printing.

Description

When compiling, I had some warnings regarding printf. I fixed them by using the correct types.

Test Steps

Compile using GCC or Clang with -Wformat.

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.

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.

ntohl() returns a u32, which is defined as an unsigned long in GCC.

> /source/FreeRTOS_IPv4.c:442:52: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'long unsigned int' [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wformat=-Wformat=8;;]
>   442 |                                 FreeRTOS_printf( ( "prvAllowIPPacket: UDP packet from %xip without CRC dropped\n",
>       |                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /build/src/FreeRTOSIPConfig.h:75:12: note: in definition of macro 'FreeRTOS_printf'
>    75 |     printf X
>       |            ^
> /source/FreeRTOS_IPv4.c:442:88: note: format string is defined here
>   442 |                                 FreeRTOS_printf( ( "prvAllowIPPacket: UDP packet from %xip without CRC dropped\n",
>       |                                                                                       ~^
>       |                                                                                        |
>       |                                                                                        unsigned int
>       |                                                                                       %lx
ntohl() returns a u32, which is defined as an unsigned int in Clang.
So we need to explicitely upper cast it into unsigned long.

Fixes this Clang warnining:

> /source/FreeRTOS_IPv4.c:443:52: warning: format specifies type 'unsigned long' but the argument has type 'uint32_t' (aka 'unsigned int') [-Wformat]
>   442 |                                 FreeRTOS_printf( ( "prvAllowIPPacket: UDP packet from %lxip without CRC dropped\n",
>       |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>       |                                                                                       %x
>   443 |                                                    FreeRTOS_ntohl( pxIPPacket->xIPHeader.ulSourceIPAddress ) ) );
>       |                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /source/include/FreeRTOS_IP.h:252:32: note: expanded from macro 'FreeRTOS_ntohl'
>   252 | #define FreeRTOS_ntohl( x )    FreeRTOS_htonl( x )
>       |                                ^
> /source/include/FreeRTOS_IP.h:233:5: note: expanded from macro 'FreeRTOS_htonl'
>   233 |     (                                                              \
>       |     ^
> /build/src/FreeRTOSIPConfig.h:75:12: note: expanded from macro 'FreeRTOS_printf'
>    75 |     printf X
>       |            ^
Fixes Clang warnings of this type:

> /source/FreeRTOS_DHCP.c:405:87: warning: format specifies type 'unsigned long' but the argument has type 'TickType_t' (aka 'unsigned int') [-Wformat]
>   405 |                         FreeRTOS_debug_printf( ( "vDHCPProcess: timeout %lu ticks\n", EP_DHCPData.xDHCPTxPeriod ) );
>       |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>       |                                                                         %u
> /source/FreeRTOS_DHCP.c:59:33: note: expanded from macro 'EP_DHCPData'
>    59 |     #define EP_DHCPData         pxEndPoint->xDHCPData               /**< Temporary define to make /single source similar to /multi version. */
>       |                                 ^
> /build/src/FreeRTOSIPConfig.h:60:12: note: expanded from macro 'FreeRTOS_debug_printf'
>    60 |     printf X
>       |            ^
@concatime concatime requested a review from a team as a code owner February 2, 2025 00:04
Copy link
Contributor

@thirtytwobits thirtytwobits left a comment

Choose a reason for hiding this comment

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

We need to remove $<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wno-format> from CMakeLists.txt or this will just keep happening.

Sorry. That comment was meant for the kernel repository.

@tony-josi-aws
Copy link
Member

@concatime

Thanks for contributing to FreeRTOS+TCP.

@ig15 ig15 merged commit 03d870d into FreeRTOS:main Feb 3, 2025
10 checks passed
@concatime concatime deleted the fix-printf-warnings branch February 20, 2025 21:09
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