commit | 39aca01d21fb85809e5690b6b3331d247c475d80 | [log] [tgz] |
---|---|---|
author | Armando Montanez <amontanez@google.com> | Mon Jan 08 22:32:53 2024 +0000 |
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | Mon Jan 08 22:32:53 2024 +0000 |
tree | 197e1cee9120d38ad68546303e796093f669eb13 | |
parent | e4224c5161e81d6550a1a4eaa15d17602cd660b1 [diff] |
pw_stream: Make stream adapters use reinterpret_cast pw_stream uses static_cast() to cast types up to a generic Stream and then down to a smaller API subset (e.g. stream::Writer) using static cast. This downcast can sometimes be to a completely different type. While in practice this is usually fine, it technically relies on undefined behavior, which is caught during fuzz testing. This change changes the relevant static_cast() calls to be reinterpret_cast() to do two things: 1. Prevent UBSAN from tripping. 2. More clearly illustrate that *technically* pw::stream::Stream relies on undefined behavior when casting. Fixes: b/314829006 Change-Id: I7b5afb72e07cd8a9969223cab7ea91711ab00542 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/186766 Reviewed-by: Taylor Cramer <cramertj@google.com> Commit-Queue: Armando Montanez <amontanez@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com>
Pigweed is an open source collection of embedded-targeted libraries–or as we like to call them, modules. These modules are building blocks and infrastructure that enable faster and more reliable development on small-footprint MMU-less 32-bit microcontrollers like the STMicroelectronics STM32L452 or the Nordic nRF52832.
For more information please see our website: https://pigweed.dev/.