diff options
| author | 2021-10-14 13:11:08 -0400 | |
|---|---|---|
| committer | 2021-10-14 14:09:34 -0400 | |
| commit | 0d6057b2fa98f08a461edaf584e9ac75f7fdecde (patch) | |
| tree | 8c641f7adf5387c40601cd335bac9bd4097c815b /src/common/string_util.cpp | |
| parent | string_util: Prevent out of bounds access in u16string_view buffer (diff) | |
| download | yuzu-0d6057b2fa98f08a461edaf584e9ac75f7fdecde.tar.gz yuzu-0d6057b2fa98f08a461edaf584e9ac75f7fdecde.tar.xz yuzu-0d6057b2fa98f08a461edaf584e9ac75f7fdecde.zip | |
string_util: Make use of std::string_view and add bounds checking
Makes use of std::string_view in StringFromFixedZeroTerminatedBuffer and add bounds checking
Diffstat (limited to 'src/common/string_util.cpp')
| -rw-r--r-- | src/common/string_util.cpp | 8 |
1 files changed, 4 insertions, 4 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 | ||
| 183 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len) { | 183 | std::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 | ||
| 191 | std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, | 191 | std::u16string UTF16StringFromFixedZeroTerminatedBuffer(std::u16string_view buffer, |