dmnt: Truncate cheat names after maxlen instead of failing

This commit is contained in:
Michael Scire authored and SciresM committed 2019-09-18 11:54:30 -07:00
1 parent fe2dd671fb
commit 89c484414b
1 file changed
+6 -6
@@ -739,13 +739,13 @@ namespace sts::dmnt::cheat::impl {
size_t j = i + 1;
while (s[j] != ']') {
j++;
if (j >= len || (j - i - 1) >= sizeof(cur_entry->definition.readable_name)) {
if (j >= len) {
return false;
}
}
/* s[i+1:j] is cheat name. */
const size_t cheat_name_len = (j - i - 1);
const size_t cheat_name_len = std::min(j - i - 1, sizeof(cur_entry->definition.readable_name));
std::memcpy(cur_entry->definition.readable_name, &s[i+1], cheat_name_len);
cur_entry->definition.readable_name[cheat_name_len] = 0;
@@ -764,13 +764,13 @@ namespace sts::dmnt::cheat::impl {
size_t j = i + 1;
while (s[j] != '}') {
j++;
if (j >= len || (j - i - 1) >= sizeof(cur_entry->definition.readable_name)) {
if (j >= len) {
return false;
}
}
/* s[i+1:j] is cheat name. */
const size_t cheat_name_len = (j - i - 1);
const size_t cheat_name_len = std::min(j - i - 1, sizeof(cur_entry->definition.readable_name));
memcpy(cur_entry->definition.readable_name, &s[i+1], cheat_name_len);
cur_entry->definition.readable_name[cheat_name_len] = 0;
@@ -837,13 +837,13 @@ namespace sts::dmnt::cheat::impl {
size_t j = i + 1;
while (s[j] != ']') {
j++;
if (j >= len || (j - i - 1) >= sizeof(cur_cheat_name)) {
if (j >= len) {
return false;
}
}
/* s[i+1:j] is cheat name. */
const size_t cheat_name_len = (j - i - 1);
const size_t cheat_name_len = std::min(j - i - 1, sizeof(cur_cheat_name));
std::memcpy(cur_cheat_name, &s[i+1], cheat_name_len);
cur_cheat_name[cheat_name_len] = 0;