Codefix: std::string_view::data() is not necessarily null terminated. (#13891)

This commit is contained in:
frosch
2025-03-25 20:32:19 +01:00
committed by GitHub
parent 93016b9a92
commit 25005cff16
7 changed files with 10 additions and 9 deletions

View File

@@ -108,9 +108,9 @@ const FiosItem *FileList::FindItem(const std::string_view file)
}
/* If no name matches, try to parse it as number */
char *endptr;
int i = std::strtol(file.data(), &endptr, 10);
if (file.data() == endptr || *endptr != '\0') i = -1;
int i;
const char *endptr = std::from_chars(file.data(), file.data() + file.size(), i, 10).ptr;
if (file.data() == endptr || endptr != file.data() + file.size()) i = -1;
if (IsInsideMM(i, 0, this->size())) return &this->at(i);