Commit Graph
3 Commits
Author SHA1 Message Date
Gennaro Prota 62ed5ee17a Fix basic_static_cstring::compare(const CharT*) for over-long inputs
compare(const CharT* s) constructed a temporary basic_static_cstring<N>
from s and delegated to the class-type overload. The constructor throws
std::length_error when traits::length(s) > N, and because compare() is
noexcept, the throw led to std::terminate():

  static_cstring<3> s("abc");
  s.compare("abcd");              // terminate() via noexcept throw

The free operator==() / operator!=() overloads for const CharT*, which
delegate to compare(), had the same flaw.
2026-04-21 16:13:29 +02:00
Gennaro Prota c6cd8074ab Fix the comparison operators for basic_static_cstring
The defaulted operators had the wrong semantics, as they compared the
entire data_ buffer. The bug showed up when shrinking:

  static_cstring<10> s("hello");
  s.assign("hi", 2);              // data_[3..4] still "lo"
  static_cstring<10> fresh("hi");
  assert(s == fresh);             // FAILED
2026-04-21 11:59:41 +02:00
Gennaro Prota e9313dc331 Add an experimental basic_static_cstring template in example/
This introduces an alternative to basic_static_string designed for use
in POD types: Trivially copyable, having a sizeof == N + 1, with no
embedded NULs.

Placed in example/ to gather user feedback before committing to a public
API. See issue #23.
2025-12-19 19:32:30 +01:00