1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-21 23:45:42 +02:00

Fix note about undefined behavior (#2632)

This commit is contained in:
Nicole L 2025-02-11 10:41:33 -08:00 committed by GitHub
parent d998022f75
commit d732821edb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -33,9 +33,8 @@ Key points:
- The second argument to `slice::from_raw_parts` is the number of _elements_, - The second argument to `slice::from_raw_parts` is the number of _elements_,
not bytes! This example demonstrates unexpected behavior by reading past the not bytes! This example demonstrates unexpected behavior by reading past the
end of one array and into another. end of one array and into another.
- This is not actually undefined behaviour, as `KeyPair` has a defined - This is undefined behavior because we're reading past the end of the array
representation (due to `repr(C)`) and no padding, so the contents of the that the pointer was derived from.
second array is also valid to read through the same pointer.
- `log_public_key` should be unsafe, because `pk_ptr` must meet certain - `log_public_key` should be unsafe, because `pk_ptr` must meet certain
prerequisites to avoid undefined behaviour. A safe function which can cause prerequisites to avoid undefined behaviour. A safe function which can cause
undefined behaviour is said to be `unsound`. What should its safety undefined behaviour is said to be `unsound`. What should its safety