summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/string_util.cpp8
-rw-r--r--src/common/string_util.h2
2 files changed, 5 insertions, 5 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 9617c3fa3..662171138 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -180,12 +180,12 @@ std::wstring UTF8ToUTF16W(const std::string& input) {
180 180
181#endif 181#endif
182 182
183std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len) { 183std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, std::size_t max_len) {
184 std::size_t len = 0; 184 std::size_t len = 0;
185 while (len < max_len && buffer[len] != '\0') 185 while (len < buffer.length() && len < max_len && buffer[len] != '\0') {
186 ++len; 186 ++len;
187 187 }
188 return std::string(buffer, len); 188 return std::string(buffer.begin(), buffer.begin() + len);
189} 189}
190 190
191std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, 191std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer,
diff --git a/src/common/string_util.h b/src/common/string_util.h
index 7e90a9ca5..f0dd632ee 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -63,7 +63,7 @@ template <typename InIt>
63 * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't 63 * Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't
64 * NUL-terminated then the string ends at max_len characters. 64 * NUL-terminated then the string ends at max_len characters.
65 */ 65 */
66[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, 66[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer,
67 std::size_t max_len); 67 std::size_t max_len);
68 68
69/** 69/**