News for hackers. Stuff that matters.
Re:Patching around a C++ crash with a little bit of Lua by tines on Sunday December 10, 2023 @09:11PM (#38596909)
To be clear, the C++ `std::string` class can contain NUL bytes just fine. It's the C standard library that can't handle them in strings.
Re:Patching around a C++ crash with a little bit of Lua by tialaramex on Monday December 11, 2023 @05:45AM (#38599386)
Sure, but alas std::string is just a library convenience type similar to Java's StringBuilder, until fairly recently C++ didn't provide the simple fat pointer now named std::string_view so for a string we're just reading C's char* often ends up used instead in practice.

Would that guess definitely be correct? No. Is it a reasonable guess for code which is apparently untested and buggy? I think so.

Re:Patching around a C++ crash with a little bit of Lua by nly on Monday December 11, 2023 @05:35PM (#38606416)
Before string_view, in my experience, people tended to pass around strings by const&
Re:Patching around a C++ crash with a little bit of Lua by tialaramex on Wednesday December 13, 2023 @07:45AM (#38626546)
If I've got a std::string I can totally see passing it as a const reference. If I've got 418 bytes of RAM that I'm slicing up into "strings", how can I make the const &std::string I need from that? I could make a std::string_view easily enough, but the std::string wants to own the memory allocation, and it can't have that because it's mine. So now I'm either allocating and copying (bye bye performance) or I pass char*.

Because C++ loves implicit conversion this works even when the API didn't intend char* because it just calls the constructor on std::string to make one from the pointer. "Hooray"