The if (*cstr_end == '\0') in the previous code checked if the previous loop terminated because it
found a null terminator or because it reached the end of the data. However, in the case that we hit
the end of the data before finding a null terminator, cstr_end points behind the last byte in our
data and *cstr_end reads the memory behind the array (which may be uninitialised)
This patch just rewrites that function use std::find and adds the relevant unit tests.