diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index 8b553e079..a0e7943ca 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -91,7 +91,7 @@ static const wchar_t *string_get_arg_stdin(wcstring *storage, const io_streams_t } // Split the buffer on the '\n' and return the first part. - *storage = str2wcstring(buffer.c_str(), pos); + *storage = str2wcstring(buffer, pos); buffer.erase(0, pos + 1); return storage->c_str(); } diff --git a/src/common.cpp b/src/common.cpp index 9d78b5f59..d8650c0d9 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -290,6 +290,11 @@ wcstring str2wcstring(const std::string &in) { return str2wcs_internal(in.data(), in.size()); } +wcstring str2wcstring(const std::string &in, size_t len) { + // Handles embedded nulls! + return str2wcs_internal(in.data(), len); +} + char *wcs2str(const wchar_t *in) { if (!in) return NULL; size_t desired_size = MAX_UTF8_BYTES * wcslen(in) + 1; diff --git a/src/common.h b/src/common.h index 6d6b2e905..54165cd20 100644 --- a/src/common.h +++ b/src/common.h @@ -285,6 +285,7 @@ int fgetws2(wcstring *s, FILE *f); wcstring str2wcstring(const char *in); wcstring str2wcstring(const char *in, size_t len); wcstring str2wcstring(const std::string &in); +wcstring str2wcstring(const std::string &in, size_t len); /// Returns a newly allocated multibyte character string equivalent of the specified wide character /// string.