Skip to content

Some code transformations required to allow -fbounds-safety to compile - #1686

Merged
seanm merged 2 commits into
libusb:masterfrom
seanm:fbounds-safety-prep
Jun 4, 2026
Merged

seanm merged 2 commits into
libusb:masterfrom
seanm:fbounds-safety-prep

Conversation

@seanm

@seanm seanm commented Aug 26, 2025

Copy link
Copy Markdown
Contributor

Should be no change in behaviour.

@mcuee mcuee added the core Related to common codes label Aug 27, 2025
Comment thread libusb/os/events_posix.c Resolved
@seanm
seanm force-pushed the fbounds-safety-prep branch from 7913519 to 40aee85 Compare August 28, 2025 16:09
@seanm

seanm commented Sep 15, 2025

Copy link
Copy Markdown
Contributor Author

@sonatique what do you think?

@seanm seanm mentioned this pull request Sep 18, 2025
@mcuee

mcuee commented Sep 19, 2025

Copy link
Copy Markdown
Member

@tormodvolden

Are you fine with this PR now? Thanks.

Comment thread libusb/libusb.h Resolved
@mcuee

mcuee commented Oct 17, 2025

Copy link
Copy Markdown
Member

Pending review from @tormodvolden

I'd prefer to keep this PR simple, changing as little as possible to make -fbounds-safety happy. Rehabilitating the function and all other changes make it much harder to review. We have made real regressions before while doing innocently looking rework for pleasing checking tools. I am not saying we shouldn't do those changes but they must be reviewed more deeply than I have time for now.

Comment thread libusb/os/events_posix.c Resolved
@seanm
seanm force-pushed the fbounds-safety-prep branch from 40aee85 to 99c0a93 Compare January 11, 2026 05:54
@mcuee mcuee added this to the 1.0.31 milestone Apr 13, 2026
seanm added 2 commits May 2, 2026 19:22
-fbounds-safety requires that pointer and its size are always set back-to-back with no intervening statements. Before this patch, the `if` statement was in the way.

This changes also makes sure that length is set to 0 if the pointer is NULL.
-fbounds-safety requires that pointer and its size are always set back-to-back with no intervening statements.

Before this patch, the loop was incrementing the count without also syncing the pointer, which does not compile.

Added temporary variable to count then set pointer and size back-to-back.

Also removed unneed NULL test since free(NULL) is well-defined to do nothing.
@seanm
seanm force-pushed the fbounds-safety-prep branch from 99c0a93 to c4aaf9a Compare May 2, 2026 23:22
@mcuee mcuee mentioned this pull request May 6, 2026
@seanm
seanm requested a review from Youw May 31, 2026 20:57
@seanm
seanm merged commit 09eab12 into libusb:master Jun 4, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Related to common codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants