ludocode / mpack

MPack - A C encoder/decoder for the MessagePack serialization format / msgpack.org[C]
MIT License
533 stars 82 forks source link

Warning about incompatible int types in mpack_snprintf calls #103

Closed Franky1 closed 1 year ago

Franky1 commented 2 years ago

I copied the "amalgamation package" sources to my project and compiled it with a STM32 CubeIDE compiler. Got some warnings about incompatible types:

format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=] mpack.c.line 427 C/C++ Problem
format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=] mpack.c.line 477 C/C++ Problem
format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=] mpack.c.line 489 C/C++ Problem
format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=] mpack.c.line 492 C/C++ Problem
format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=] mpack.c.line 544 C/C++ Problem
format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=] mpack.c.line 547 C/C++ Problem
format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=] mpack.c.line 556 C/C++ Problem
format '%u' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=] mpack.c.line 559 C/C++ Problem

Quickfix seems to be to replace all %u with %lu in the affected mpack_snprintf calls from above, where the compiler is complaining. Don't know if this could be fixed in the source repo here and still be platform independent?

ludocode commented 1 year ago

The correct fix for this is to use % PRIu32. Fixed in e55dcd505.