summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMai M <mathew1800@gmail.com>2021-10-15 23:04:44 +0200
committerGitHub <noreply@github.com>2021-10-15 23:04:44 +0200
commit764369f4c7ac60f6a985f613bee4a02a20afb88d (patch)
tree2333d6f81aba1757e5a88778e35ca8dc1239de36
parentMerge pull request #7174 from MightyCreak/hide-cursor-by-default (diff)
parentstring_util: Make use of std::string_view and add bounds checking (diff)
downloadyuzu-764369f4c7ac60f6a985f613bee4a02a20afb88d.tar
yuzu-764369f4c7ac60f6a985f613bee4a02a20afb88d.tar.gz
yuzu-764369f4c7ac60f6a985f613bee4a02a20afb88d.tar.bz2
yuzu-764369f4c7ac60f6a985f613bee4a02a20afb88d.tar.lz
yuzu-764369f4c7ac60f6a985f613bee4a02a20afb88d.tar.xz
yuzu-764369f4c7ac60f6a985f613bee4a02a20afb88d.tar.zst
yuzu-764369f4c7ac60f6a985f613bee4a02a20afb88d.zip
-rw-r--r--src/common/string_util.cpp12
-rw-r--r--src/common/string_util.h2
2 files changed, 7 insertions, 7 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index e6344fd41..662171138 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -180,20 +180,20 @@ std::wstring UTF8ToUTF16W(const std::string& input) {
#endif
-std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len) {
+std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, std::size_t max_len) {
std::size_t len = 0;
- while (len < max_len && buffer[len] != '\0')
+ while (len < buffer.length() && len < max_len && buffer[len] != '\0') {
++len;
-
- return std::string(buffer, len);
+ }
+ return std::string(buffer.begin(), buffer.begin() + len);
}
std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer,
std::size_t max_len) {
std::size_t len = 0;
- while (len < max_len && buffer[len] != '\0')
+ while (len < buffer.length() && len < max_len && buffer[len] != '\0') {
++len;
-
+ }
return std::u16string(buffer.begin(), buffer.begin() + len);
}
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>
* Creates a std::string from a fixed-size NUL-terminated char buffer. If the buffer isn't
* NUL-terminated then the string ends at max_len characters.
*/
-[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(const char* buffer,
+[[nodiscard]] std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer,
std::size_t max_len);
/**