未验证 提交 b2c1b28f 编写于 作者: C Chris Bracken 提交者: GitHub

Fix attribute replace bug in TextAXNodeWrapper (#24986)

When replacing an int/float/bool attribute on the test node, we want to
erase the range from the iterator returned by remove_if to end(), which
may be an empty range. In the case where remove_if() returns end(), the
single-parameter variant of erase() attempts to remove an element past
the end of the container.
上级 ce43eb6d
......@@ -369,9 +369,10 @@ void TestAXNodeWrapper::ReplaceIntAttribute(int32_t node_id,
std::vector<std::pair<ax::mojom::IntAttribute, int32_t>>& attributes =
new_data.int_attributes;
attributes.erase(std::remove_if(
auto it = std::remove_if(
attributes.begin(), attributes.end(),
[attribute](auto& pair) { return pair.first == attribute; }));
[attribute](auto& pair) { return pair.first == attribute; });
attributes.erase(it, attributes.end());
new_data.AddIntAttribute(attribute, value);
node->SetData(new_data);
......@@ -384,9 +385,10 @@ void TestAXNodeWrapper::ReplaceFloatAttribute(
std::vector<std::pair<ax::mojom::FloatAttribute, float>>& attributes =
new_data.float_attributes;
attributes.erase(std::remove_if(
auto it = std::remove_if(
attributes.begin(), attributes.end(),
[attribute](auto& pair) { return pair.first == attribute; }));
[attribute](auto& pair) { return pair.first == attribute; });
attributes.erase(it, attributes.end());
new_data.AddFloatAttribute(attribute, value);
node_->SetData(new_data);
......@@ -398,9 +400,10 @@ void TestAXNodeWrapper::ReplaceBoolAttribute(ax::mojom::BoolAttribute attribute,
std::vector<std::pair<ax::mojom::BoolAttribute, bool>>& attributes =
new_data.bool_attributes;
attributes.erase(std::remove_if(
auto it = std::remove_if(
attributes.begin(), attributes.end(),
[attribute](auto& pair) { return pair.first == attribute; }));
[attribute](auto& pair) { return pair.first == attribute; });
attributes.erase(it, attributes.end());
new_data.AddBoolAttribute(attribute, value);
node_->SetData(new_data);
......@@ -413,9 +416,10 @@ void TestAXNodeWrapper::ReplaceStringAttribute(
std::vector<std::pair<ax::mojom::StringAttribute, std::string>>& attributes =
new_data.string_attributes;
attributes.erase(std::remove_if(
auto it = std::remove_if(
attributes.begin(), attributes.end(),
[attribute](auto& pair) { return pair.first == attribute; }));
[attribute](auto& pair) { return pair.first == attribute; });
attributes.erase(it, attributes.end());
new_data.AddStringAttribute(attribute, value);
node_->SetData(new_data);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册