Skip to content

Fix sprintf deprecation warnings#1697

Merged
KrisThielemans merged 9 commits intoUCL:masterfrom
denproc:fix_sprintf_deprecation
Mar 22, 2026
Merged

Fix sprintf deprecation warnings#1697
KrisThielemans merged 9 commits intoUCL:masterfrom
denproc:fix_sprintf_deprecation

Conversation

@denproc
Copy link
Copy Markdown
Contributor

@denproc denproc commented Mar 21, 2026

Changes in this pull request

Current PR updates deprecated sprintf usage with snprintf and addresses #1586.

Testing performed

Tested on MacOS (Apple Silicon) and CUDA-enabled Linux PCs.

Related issues

Fixes #1586

Checklist before requesting a review

  • I have performed a self-review of my code
  • The code builds and runs on my machine

Contribution Notes

Please tick the following:

  • The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in STIR (the Work) under the terms and conditions of the Apache-2.0 License.
  • I (or my institution) have signed the STIR Contribution License Agreement (not required for small changes).

@KrisThielemans
Copy link
Copy Markdown
Collaborator

This is a nice and simple fix. I guess someone will have to check carefully if there's no typo. Or would the compiler flag it up if we use snprintf with the wrong size?

Copy link
Copy Markdown
Collaborator

@KrisThielemans KrisThielemans left a comment

Choose a reason for hiding this comment

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

I went throught this and it's looking good!

I suggest constexpr in a few places, but it doesn't really seem to matter, so let me know if you'd rather not do those. (If you do use github suggestion, please "batch" them up, to avoid too many CI runs).

I will squash-merge this if ok with you.

thanks a lot!

@denproc
Copy link
Copy Markdown
Contributor Author

denproc commented Mar 22, 2026

@KrisThielemans, thank you for revieweing the PR and suggesting additional changes!
I have just checked edge cases for snprintf, when buffer length and used size differ:

  • For size < length of format string, there will be a warning.
  • For size <= length of buffer, there will be no warnings, input data will be truncated to the size.
  • For size > length of buffer, there might be buffer overflow depending on input data. No warnings were produces, so it's better to double check the size used in snprintf for new entries.

I'll add your changes and am happy this PR being squash-merged.

denproc and others added 2 commits March 22, 2026 18:08
@KrisThielemans KrisThielemans added this to the v6.4 milestone Mar 22, 2026
@KrisThielemans KrisThielemans merged commit d4df167 into UCL:master Mar 22, 2026
13 checks passed
@KrisThielemans
Copy link
Copy Markdown
Collaborator

Thanks!

@denproc denproc deleted the fix_sprintf_deprecation branch March 23, 2026 17:18
@denproc denproc mentioned this pull request Mar 23, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clang warnings as sprintf deprecated

2 participants