Page MenuHomeFreeBSD

cam: fix UB behavior
ClosedPublic

Authored by imp on Jun 21 2021, 6:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 23, 9:00 PM
Unknown Object (File)
Sep 24 2024, 3:28 PM
Unknown Object (File)
Sep 18 2024, 7:03 PM
Unknown Object (File)
Sep 12 2024, 10:58 PM
Unknown Object (File)
Sep 12 2024, 6:37 PM
Unknown Object (File)
Sep 10 2024, 8:43 PM
Unknown Object (File)
Sep 8 2024, 1:04 PM
Unknown Object (File)
Sep 8 2024, 8:10 AM
Subscribers
None

Details

Reviewers
ken
mav
scottl
Group Reviewers
cam
Commits
rG56e1161b09c3: cam: fix UB behavior
Summary

The trick of subtracting one from the poitner returned from malloc
results in undefined behavior:

C89: 3.3.6 Unless both the pointer operand and the result point to a
member of the same array object, or one past the last member of the
array object, the behavior is undefined.

Instead, allocate 1 extra element and stop adjusting the pointer. While
a little wasteful, the extra is in the noise on today's systems.

Sponsored by: Netflix

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 40025
Build 36914: arc lint + arc unit

Event Timeline

imp requested review of this revision.Jun 21 2021, 6:01 PM

Thank you. This stuff always broke my brain.

This revision is now accepted and ready to land.Jun 24 2021, 3:11 AM
This revision was automatically updated to reflect the committed changes.