avoid a g++-12 warning about potential null pointer dereference
* spot/twaalgos/determinize.cc (sorted_nodes): Rewrite to avoid reallocation of temporary vector.
This commit is contained in:
parent
ba695194cd
commit
c9ba998200
1 changed files with 15 additions and 7 deletions
|
|
@ -472,15 +472,23 @@ namespace spot
|
|||
std::vector<safra_state::safra_node_t> res;
|
||||
for (const auto& n: s.nodes_)
|
||||
{
|
||||
int brace = n.second;
|
||||
std::vector<int> tmp;
|
||||
while (brace >= 0)
|
||||
// First, count the number of braces.
|
||||
unsigned nbraces = 0;
|
||||
for (int brace = n.second; brace >= 0; brace = s.braces_[brace])
|
||||
++nbraces;
|
||||
// Then list them in reverse order. Since we know the
|
||||
// number of braces, we can allocate exactly what we need.
|
||||
if (nbraces > 0)
|
||||
{
|
||||
// FIXME: is there a smarter way?
|
||||
tmp.insert(tmp.begin(), brace);
|
||||
brace = s.braces_[brace];
|
||||
std::vector<int> tmp(nbraces, 0);
|
||||
for (int brace = n.second; brace >= 0; brace = s.braces_[brace])
|
||||
tmp[--nbraces] = brace;
|
||||
res.emplace_back(n.first, std::move(tmp));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.emplace_back(n.first, std::vector<int>{});
|
||||
}
|
||||
res.emplace_back(n.first, std::move(tmp));
|
||||
}
|
||||
std::sort(res.begin(), res.end(), compare());
|
||||
return res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue