Skip to content

Conversation

@ehaas
Copy link

@ehaas ehaas commented Oct 30, 2025

Add format(printf) attribute to modlog_printf to enable compile-time checking that format strings match arguments.

Note that this will cause incorrect modlog_printf usage which previously compiled successfully, to no longer compile.

@ehaas
Copy link
Author

ehaas commented Oct 30, 2025

Note that there is pre-existing usage of __attribute__(format) in sys/console/full/include/console/console.h so it seems like ensuring compatibility with compilers that do not support GNU-style attributes is not required?

@ehaas ehaas force-pushed the modlog-format-attribute branch 3 times, most recently from 1e70331 to acedf5a Compare October 30, 2025 23:50
@github-actions github-actions bot added size/s and removed size/xs labels Oct 30, 2025
@vrahane
Copy link
Contributor

vrahane commented Nov 3, 2025

@ehaas I think once the nimble PR is merged, the CI issues will get fixed. Let's wait for that.

@vrahane vrahane requested a review from sjanc November 4, 2025 21:32
Copy link
Contributor

@sjanc sjanc left a comment

Choose a reason for hiding this comment

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

what setup is giving you those errors where int32_t is long int? we could add this to CI to avoid similar issues in future

rc = mn_sendto(oc_ucast6, n, (struct mn_sockaddr *) &to);
if (rc != 0) {
OC_LOG_ERROR("Failed to send buffer %u on itf %d\n",
OC_LOG_ERROR("Failed to send buffer %u on itf %" PRIu32 "\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm really not a huge fan of PRI syntax... especially that it leads to inconsistent print formatting, eg here you don't use PRIu16 for omp_len

what do you think on using %u here and casting msin6_scope_id to (unsigned int) ?

Copy link
Author

Choose a reason for hiding this comment

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

Updated; I also find the PRI syntax pretty ugly.

*/
void modlog_printf(uint8_t module, uint8_t level, const char *msg, ...);
void modlog_printf(uint8_t module, uint8_t level, const char *msg, ...)
__attribute((format(printf, 3, 4)));
Copy link
Contributor

Choose a reason for hiding this comment

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

modlog.h is included in a lot of modules in core, only osdp and oic require fixes for this to be enabled?

maybe it should be under MYNEWT_VAL (at least for time being) so that no unexpected build errors are introduced?

(especially that currently we always enable Werror - which we should make opt-in option anyway)

@sjanc
Copy link
Contributor

sjanc commented Nov 5, 2025

Note that there is pre-existing usage of __attribute__(format) in sys/console/full/include/console/console.h so it seems like ensuring compatibility with compilers that do not support GNU-style attributes is not required?

yeah, I guess any reasonable compiler supports this extension :)

@ehaas
Copy link
Author

ehaas commented Nov 10, 2025

what setup is giving you those errors where int32_t is long int? we could add this to CI to avoid similar issues in future

~$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 8.2.1 20181213 (release) [gcc-8-branch revision 267074]

Here is a repro on arm-none-eabi-gcc 8.3.1: https://godbolt.org/z/sTnPahqE5

Add format(printf) attribute to modlog_printf to enable compile-time
checking that format strings match arguments.

Note that this will cause incorrect modlog_printf usage which
previously compiled successfully, to no longer compile.
@ehaas ehaas force-pushed the modlog-format-attribute branch from acedf5a to de2fb82 Compare November 11, 2025 23:42
Copy link
Contributor

@sjanc sjanc left a comment

Choose a reason for hiding this comment

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

looks ok to me but please fix compliance issues reported

I guess Nimble PR also should be updated to use cast instead PRI and this should be ready for merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants