← Back to context

Comment by tremon

2 years ago

If the problem is "you're using nul-terminated strings" as the GP said, then "don't use C" a good step towards fixing that problem, no?

Perhaps, but also realistic to accept that you're using code where other people do/have and that the same logic would apply to them.

  • You only have to care about it at boundaries though, for the most part. Like, when calling a C API. That's easy to handle. Even C++'s std::string can do that, as the c_str method always returns a null-terminated string. That inherently kills the need for things like strcat.

    • The return from c_str cannot be used everywhere you would normally use a null terminated string, because the return is const.

      For example, you couldn't pass it to strtok, or any other function that needs to even temporarily modify the string.

      7 replies →