Skip to content

shared/bpm: Replace sprintf usage#13199

Open
jcm93 wants to merge 1 commit intoobsproject:masterfrom
jcm93:asan-compile-fix
Open

shared/bpm: Replace sprintf usage#13199
jcm93 wants to merge 1 commit intoobsproject:masterfrom
jcm93:asan-compile-fix

Conversation

@jcm93
Copy link
Contributor

@jcm93 jcm93 commented Mar 7, 2026

Description

Replace sprintf use in bpm with safer snprintf, providing the length of the remaining buffer space in the string as the size parameter to snprintf.

Motivation and Context

sprintf use can fire -Wdeprecated in AppleClang, causing build failures under typical -Werror OBS compilation settings.

For some reason, locally, this use of sprintf only seems to fire -Wdeprecated when the address sanitizer is on, even though it seems like we ought to be hitting it in all circumstances. Regardless, we want to be able to compile with ASAN, and sprintf use is typically unsafe, so replace with a safer alternative.

How Has This Been Tested?

Enabled BPM, made sure it is still writing correct timestamps.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@jcm93 jcm93 force-pushed the asan-compile-fix branch from fc29369 to 41ac753 Compare March 7, 2026 20:13
@jcm93
Copy link
Contributor Author

jcm93 commented Mar 7, 2026

The first version of this PR tried to be smart and assumed that "%03ld" would be no more than 3 characters in length, because it was formatting a timespec nanosecond value that had been divided by one million. This was not good enough of a guarantee for GCC, which complained that for longer long values, 3 bytes would not be enough.

The current version of the code just provides the entirety of the string's remaining buffer space as the size parameter to snprintf.

@WizardCM WizardCM added Bug Fix Non-breaking change which fixes an issue Code Cleanup Non-breaking change which makes code smaller or more readable labels Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Fix Non-breaking change which fixes an issue Code Cleanup Non-breaking change which makes code smaller or more readable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants