FIX:Avoid array out of bounds

jira: none
Change-Id: I1ef5921a11ec7f9e2fc40edad4e954474628f7b5
This commit is contained in:
zhou.xu 2025-02-17 20:37:18 +08:00 committed by lane.wei
parent 46327afd10
commit 2ca82b096e
1 changed files with 7 additions and 1 deletions

View File

@ -2030,14 +2030,20 @@ unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns, bool use_map, s
for (size_t i = 0; i < exist_colors.size(); i++) {
if (maps.find(i) != maps.end()) {//mapping exist
auto valid_index = get_map_index(ams_array_maps, maps[i]);
if (valid_index >= 0) {
if (valid_index >= 0 && valid_index < ams_filament_presets.size()) {
exist_colors[i] = ams_filament_colors[valid_index];
exist_filament_presets[i] = ams_filament_presets[valid_index];
} else {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "check error: array bound (mapping exist)";
}
}
}
for (size_t i = 0; i < ams_infos.size(); i++) {// check append
if (ams_infos[i].valid) {
if (i >= ams_filament_presets.size()) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "check error: array bound (check append)";
continue;
}
ams_infos[i].filament_preset = ams_filament_presets[i];
if (!ams_infos[i].is_map) {
need_append_colors.emplace_back(ams_infos[i]);