|author||Wyatt Hepler <email@example.com>||Wed Sep 28 00:47:36 2022 +0000|
|committer||CQ Bot Account <firstname.lastname@example.org>||Wed Sep 28 00:47:36 2022 +0000|
pw_string: Match std::string semantics for literal / array overloads Previously, the constructor, assign, and append overloads for string literals or arrays used the length of the array as the length of the string, and dropped the final character only if it was a null terminator. This avoided some strlen() calls and made assigning to an InlineString more like working with an ""sv string literal. However, since the character array is not guaranteed to be null terminated, this approach had some drawbacks: - A string of length N could not be assigned to an InlineString<N>, to account for non-terminated character arrays. - The capacity template argument would be deduced to a value one larger than the length of the string. - Behavior was inconsistent with std::string, since nulls could be included in assignments. This commit updates pw::InlineString's string literal or array overloads to use the same semantics as std::string. Unlike std::string, pw::InlineString checks the array size to prevent out-of-bounds reads. Change-Id: Ic0e61fd1c45847f5a0b6affa414ed0e624b09807 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/111711 Pigweed-Auto-Submit: Wyatt Hepler <email@example.com> Reviewed-by: Erik Gilling <firstname.lastname@example.org> Commit-Queue: Auto-Submit <email@example.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/.