We ran the Coverity static analysis tool on GDB and it pointed out some
instances of "use after move" in GDB. The instances that could be easily
removed are related to move constructors for exceptions, that were using
the parameter's reason in an assert, when they could instead just use
their own internal "reason" member. One such example is the following:
Error: USE_AFTER_MOVE (CWE-457):
gdb-17.1/gdbsupport/common-exceptions.h:281:7: move: "ex" is moved (indicated by "std::move(ex)").
gdb-17.1/gdbsupport/common-exceptions.h:283:5: use_after_move: "ex" is used after it has been already moved.
# 281| : gdb_exception (std::move (ex))
# 282| {
# 283|-> gdb_assert (ex.reason == RETURN_ERROR);
# 284| }
# 285| };
This patch fixes that small oversight.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
explicit gdb_exception_error (gdb_exception &&ex) noexcept
: gdb_exception (std::move (ex))
{
- gdb_assert (ex.reason == RETURN_ERROR);
+ gdb_assert (reason == RETURN_ERROR);
}
};
explicit gdb_exception_quit (gdb_exception &&ex) noexcept
: gdb_exception (std::move (ex))
{
- gdb_assert (ex.reason == RETURN_QUIT);
+ gdb_assert (reason == RETURN_QUIT);
}
};
explicit gdb_exception_forced_quit (gdb_exception &&ex) noexcept
: gdb_exception (std::move (ex))
{
- gdb_assert (ex.reason == RETURN_FORCED_QUIT);
+ gdb_assert (reason == RETURN_FORCED_QUIT);
}
};