commit | 71a3266aa316744d980bf2a4eb3d4129923ce99f | [log] [tgz] |
---|---|---|
author | Wyatt Hepler <hepler@google.com> | Wed Sep 28 00:47:36 2022 +0000 |
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | Wed Sep 28 00:47:36 2022 +0000 |
tree | 69411123e996a637c6308240593d2b324c1014e9 | |
parent | 3da49f09465804b65240884e10c76636086fd3bc [diff] |
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 <hepler@google.com> Reviewed-by: Erik Gilling <konkers@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.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/.