Reject `StringData((const char*)0)`

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Programmability
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None

      This is UB under std::string_view, but StringData accepts it.
      To convert to std::string_view we would need to stop relying on this.

      Add an invariant to the body of this constructor to ensure that we don't use it.

      Possibly create a helper function that can be used where we might want to accept null pointers. Which could be something like:

      constexpr StringData nullSafeStringData(const char* s) noexcept {
          return s ? StringData{s} : StringData{};
      }
      

      Add a

      {[[gnu::nonnull]]}

      to the function declaration. This could unlock some small incidental optimizations as a side effect.

            Assignee:
            Unassigned
            Reporter:
            Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: