Skip to content

Commit

Permalink
Merge pull request The-OpenROAD-Project#5049 from gadfort/coverity
Browse files Browse the repository at this point in the history
pdn/psm/gui: coverity report
  • Loading branch information
maliberty authored May 6, 2024
2 parents fd1b211 + d1c745d commit 860e03a
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/gui/include/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Descriptor
virtual std::string getName(std::any object) const = 0;
virtual std::string getShortName(std::any object) const
{
return getName(object);
return getName(std::move(object));
}
virtual std::string getTypeName() const = 0;
virtual std::string getTypeName(std::any /* object */) const
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/browserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void BrowserWidget::clicked(const QModelIndex& index)
Selected sel = getSelectedFromIndex(index);

if (sel) {
emit select({sel});
emit select({std::move(sel)});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gui/src/bufferTreeDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ Descriptor::Actions BufferTreeDescriptor::getActions(std::any object) const
is_focus &= focus_nets_.count(net) != 0;
}
if (!is_focus) {
actions.push_back(Descriptor::Action{"Focus", [this, gui, bnet]() {
actions.push_back(Descriptor::Action{"Focus", [this, gui, &bnet]() {
for (auto* net : bnet.getNets()) {
gui->addFocusNet(net);
}
return makeSelected(bnet);
}});
} else {
actions.push_back(Descriptor::Action{"De-focus", [this, gui, bnet]() {
actions.push_back(Descriptor::Action{"De-focus", [this, gui, &bnet]() {
for (auto* net : bnet.getNets()) {
gui->removeFocusNet(net);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/clockWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ ClockTreeView::ClockTreeView(std::shared_ptr<ClockTree> tree,
utl::Logger* logger,
QWidget* parent)
: QGraphicsView(new ClockTreeScene(parent), parent),
tree_(tree),
tree_(std::move(tree)),
renderer_(std::make_unique<ClockTreeRenderer>(tree_.get())),
renderer_state_(RendererState::OnlyShowOnActiveWidget),
scene_(nullptr),
Expand Down
38 changes: 19 additions & 19 deletions src/gui/src/dbDescriptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void populateODBProperties(Descriptor::Properties& props,
if (!prefix.empty()) {
prop_name = prefix + " " + prop_name;
}
props.push_back({prop_name, prop_list});
props.push_back({std::move(prop_name), prop_list});
}
}

Expand Down Expand Up @@ -217,7 +217,7 @@ static odb::dbTechLayer* getLayerSelection(odb::dbTech* tech,
std::vector<Descriptor::EditorOption> options;
addLayersToOptions(tech, options);
QStringList layers;
for (auto& [name, layer] : options) {
for (const auto& [name, layer] : options) {
layers.append(QString::fromStdString(name));
}
bool okay;
Expand Down Expand Up @@ -1391,8 +1391,8 @@ void DbNetDescriptor::highlight(std::any object, Painter& painter) const
auto color = painter.getPenColor();
color.a = 255;
painter.setPen(color, true);
for (auto& driver : driver_locs) {
for (auto& sink : sink_locs) {
for (const auto& driver : driver_locs) {
for (const auto& sink : sink_locs) {
painter.drawLine(driver, sink);
}
}
Expand Down Expand Up @@ -1596,18 +1596,18 @@ bool DbNetDescriptor::getAllObjects(SelectionSet& objects) const
return true;
}

odb::dbNet* DbNetDescriptor::getNet(std::any object) const
odb::dbNet* DbNetDescriptor::getNet(const std::any& object) const
{
odb::dbNet** net = std::any_cast<odb::dbNet*>(&object);
odb::dbNet* const* net = std::any_cast<odb::dbNet*>(&object);
if (net != nullptr) {
return *net;
}
return std::any_cast<NetWithSink>(object).net;
}

odb::dbObject* DbNetDescriptor::getSink(std::any object) const
odb::dbObject* DbNetDescriptor::getSink(const std::any& object) const
{
NetWithSink* net_sink = std::any_cast<NetWithSink>(&object);
const NetWithSink* net_sink = std::any_cast<NetWithSink>(&object);
if (net_sink != nullptr) {
return net_sink->sink;
}
Expand Down Expand Up @@ -1679,15 +1679,15 @@ Descriptor::Properties DbITermDescriptor::getProperties(std::any object) const
net_value = "<none>";
}
SelectionSet aps;
for (auto& [mpin, ap_vec] : iterm->getAccessPoints()) {
for (auto ap : ap_vec) {
for (const auto& [mpin, ap_vec] : iterm->getAccessPoints()) {
for (const auto& ap : ap_vec) {
DbTermAccessPoint iap{ap, iterm};
aps.insert(gui->makeSelected(iap));
}
}
Properties props{{"Instance", gui->makeSelected(iterm->getInst())},
{"IO type", iterm->getIoType().getString()},
{"Net", net_value},
{"Net", std::move(net_value)},
{"Special", iterm->isSpecial()},
{"MTerm", iterm->getMTerm()->getConstName()},
{"Access Points", aps}};
Expand Down Expand Up @@ -2047,7 +2047,7 @@ Descriptor::Properties DbBlockageDescriptor::getProperties(
odb::Rect rect = blockage->getBBox()->getBox();
Properties props{
{"Block", gui->makeSelected(blockage->getBlock())},
{"Instance", inst_value},
{"Instance", std::move(inst_value)},
{"X", Property::convert_dbu(rect.xMin(), true)},
{"Y", Property::convert_dbu(rect.yMin(), true)},
{"Width", Property::convert_dbu(rect.dx(), true)},
Expand Down Expand Up @@ -2148,7 +2148,7 @@ bool DbObstructionDescriptor::getBBox(std::any object, odb::Rect& bbox) const
void DbObstructionDescriptor::highlight(std::any object, Painter& painter) const
{
odb::Rect rect;
getBBox(object, rect);
getBBox(std::move(object), rect);
painter.drawRect(rect);
}

Expand Down Expand Up @@ -2358,7 +2358,7 @@ Descriptor::Properties DbTechLayerDescriptor::getProperties(
for (auto width : width_table->getWidthTable()) {
widths.emplace_back(Property::convert_dbu(width, true));
}
props.push_back({title, widths});
props.push_back({std::move(title), widths});
}

PropertyList cutclasses;
Expand Down Expand Up @@ -3880,26 +3880,26 @@ bool DbSiteDescriptor::getAllObjects(SelectionSet& objects) const
return true;
}

odb::dbSite* DbSiteDescriptor::getSite(std::any object) const
odb::dbSite* DbSiteDescriptor::getSite(const std::any& object) const
{
odb::dbSite** site = std::any_cast<odb::dbSite*>(&object);
odb::dbSite* const* site = std::any_cast<odb::dbSite*>(&object);
if (site != nullptr) {
return *site;
}
SpecificSite ss = std::any_cast<SpecificSite>(object);
return ss.site;
}

odb::Rect DbSiteDescriptor::getRect(std::any object) const
odb::Rect DbSiteDescriptor::getRect(const std::any& object) const
{
SpecificSite* ss = std::any_cast<SpecificSite>(&object);
const SpecificSite* ss = std::any_cast<SpecificSite>(&object);
if (ss != nullptr) {
return ss->rect;
}
return odb::Rect();
}

bool DbSiteDescriptor::isSpecificSite(std::any object) const
bool DbSiteDescriptor::isSpecificSite(const std::any& object) const
{
return std::any_cast<SpecificSite>(&object) != nullptr;
}
Expand Down
10 changes: 5 additions & 5 deletions src/gui/src/dbDescriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ class DbNetDescriptor : public Descriptor
const std::set<odb::dbNet*>& guide_nets_;
const std::set<odb::dbNet*>& tracks_nets_;

odb::dbNet* getNet(std::any object) const;
odb::dbObject* getSink(std::any object) const;
odb::dbNet* getNet(const std::any& object) const;
odb::dbObject* getSink(const std::any& object) const;

static const int max_iterms_ = 10000;
};
Expand Down Expand Up @@ -660,9 +660,9 @@ class DbSiteDescriptor : public Descriptor
private:
odb::dbDatabase* db_;

odb::dbSite* getSite(std::any object) const;
odb::Rect getRect(std::any object) const;
bool isSpecificSite(std::any object) const;
odb::dbSite* getSite(const std::any& object) const;
odb::Rect getRect(const std::any& object) const;
bool isSpecificSite(const std::any& object) const;
};

class DbRowDescriptor : public Descriptor
Expand Down
6 changes: 3 additions & 3 deletions src/gui/src/displayControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ QVariant DisplayControlModel::data(const QModelIndex& index, int role) const
QString information;

auto add_prop
= [props](const std::string& prop, QString& info) -> bool {
= [&props](const std::string& prop, QString& info) -> bool {
auto prop_find = std::find_if(
props.begin(), props.end(), [prop](const auto& p) {
return p.name == prop;
Expand Down Expand Up @@ -1067,7 +1067,7 @@ void DisplayControls::displayItemDblClicked(const QModelIndex& index)
cut_color_item->setIcon(makeSwatchIcon(chosen_color));
}
}
*item_color = chosen_color;
*item_color = std::move(chosen_color);
if (item_pattern != nullptr) {
*item_pattern = display_dialog->getSelectedPattern();
}
Expand Down Expand Up @@ -1929,7 +1929,7 @@ void DisplayControls::techInit(odb::dbTech* tech)
continue;
}
color.setAlpha(180);
layer_color_[layer] = color;
layer_color_[layer] = std::move(color);
layer_pattern_[layer] = Qt::SolidPattern; // Default pattern is fill solid
}
techs_.insert(tech);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/drcWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ void DRCWidget::loadJSONReport(const QString& filename)
shapes.emplace_back(
DRCViolation::DRCLine(shape_points[2], shape_points[3]));
} else if (shape_type == "polygon") {
shapes.emplace_back(DRCViolation::DRCPoly(shape_points));
shapes.emplace_back(DRCViolation::DRCPoly(std::move(shape_points)));
} else {
logger_->error(
utl::GUI, 58, "Unable to parse violation shape: {}", shape_type);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ void Gui::setHeatMapSetting(const std::string& name,
options.join(", ").toStdString());
}

auto current_value = settings[option];
auto& current_value = settings[option];
if (std::holds_alternative<bool>(current_value)) {
// is bool
if (auto* s = std::get_if<bool>(&value)) {
Expand Down
10 changes: 5 additions & 5 deletions src/gui/src/heatMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ Renderer::Settings HeatMapDataSource::getSettings() const

for (const auto& setting : settings_) {
if (std::holds_alternative<MapSettingBoolean>(setting)) {
auto set = std::get<MapSettingBoolean>(setting);
const auto& set = std::get<MapSettingBoolean>(setting);
settings[set.name] = set.getter();
} else if (std::holds_alternative<MapSettingMultiChoice>(setting)) {
auto set = std::get<MapSettingMultiChoice>(setting);
const auto& set = std::get<MapSettingMultiChoice>(setting);
settings[set.name] = set.getter();
}
}
Expand All @@ -321,12 +321,12 @@ void HeatMapDataSource::setSettings(const Renderer::Settings& settings)

for (const auto& setting : settings_) {
if (std::holds_alternative<MapSettingBoolean>(setting)) {
auto set = std::get<MapSettingBoolean>(setting);
const auto& set = std::get<MapSettingBoolean>(setting);
bool temp_value = set.getter();
Renderer::setSetting<bool>(settings, set.name, temp_value);
set.setter(temp_value);
} else if (std::holds_alternative<MapSettingMultiChoice>(setting)) {
auto set = std::get<MapSettingMultiChoice>(setting);
const auto& set = std::get<MapSettingMultiChoice>(setting);
std::string temp_value = set.getter();
Renderer::setSetting<std::string>(settings, set.name, temp_value);
set.setter(temp_value);
Expand Down Expand Up @@ -440,7 +440,7 @@ void HeatMapDataSource::setupMap()
map_pt->value = 0.0;
map_pt->color = default_color;

map_[x][y] = map_pt;
map_[x][y] = std::move(map_pt);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/heatMapSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void HeatMapSetup::addMultiChoiceOption(

QObject::connect(combo_box,
&QComboBox::currentTextChanged,
[this, option](const QString& value) {
[this, &option](const QString& value) {
option.setter(value.toStdString());
destroyMap();
source_.redraw();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/src/inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void SelectedItemModel::updateObject()
// make editor if found
auto editor_found = editors.find(prop.name);
if (editor_found != editors.end()) {
auto editor = (*editor_found).second;
auto& editor = (*editor_found).second;
makeItemEditor(prop.name,
value_item,
object_,
Expand Down Expand Up @@ -1028,7 +1028,7 @@ void Inspector::update(const Selected& object)

void Inspector::handleAction(QWidget* action)
{
auto callback = actions_[action];
auto& callback = actions_[action];
Selected new_selection;
try {
new_selection = callback();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ void MainWindow::timingPathsThrough(const std::set<Gui::odbTerm>& terms)
for (const auto& term : terms) {
pins.insert(settings->convertTerm(term));
}
settings->setThruPin({pins});
settings->setThruPin({std::move(pins)});
settings->setToPin({});

timing_widget_->updatePaths();
Expand Down
7 changes: 4 additions & 3 deletions src/gui/src/renderThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ void RenderThread::drawInstanceNames(QPainter* painter,
QString name = inst->getName().c_str();
auto master = inst->getMaster();
auto center = master->isBlock() || master->isPad();
drawTextInBBox(text_color, text_font, instance_box, name, painter, center);
drawTextInBBox(
text_color, text_font, instance_box, std::move(name), painter, center);
}
painter->setFont(initial_font);
}
Expand Down Expand Up @@ -1404,7 +1405,7 @@ void RenderThread::drawModuleView(QPainter* painter,
continue;
}

const auto setting = viewer_->modules_.at(module);
const auto& setting = viewer_->modules_.at(module);

if (!setting.visible) {
continue;
Expand Down Expand Up @@ -1449,7 +1450,7 @@ void RenderThread::setupIOPins(odb::dbBlock* block, const odb::Rect& bounds)
QString current_text = QString::fromStdString(pin->getName());
if (font_metrics.boundingRect(current_text).width()
> font_metrics.boundingRect(largest_text).width()) {
largest_text = current_text;
largest_text = std::move(current_text);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/gui/src/staGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ void TimingPathsModel::sort(int col_index, Qt::SortOrder sort_order)
beginResetModel();

if (sort_order == Qt::AscendingOrder) {
std::stable_sort(timing_paths_.begin(), timing_paths_.end(), sort_func);
std::stable_sort(
timing_paths_.begin(), timing_paths_.end(), std::move(sort_func));
} else {
std::stable_sort(timing_paths_.rbegin(), timing_paths_.rend(), sort_func);
std::stable_sort(
timing_paths_.rbegin(), timing_paths_.rend(), std::move(sort_func));
}

endResetModel();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/staGuiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ ConeDepthMapPinSet STAGuiInterface::getFanoutCone(const sta::Pin* pin) const
0,
true, // thru_disabled
true); // thru_constants
return getCone(pin, pins, false);
return getCone(pin, std::move(pins), false);
}

ConeDepthMapPinSet STAGuiInterface::getCone(const sta::Pin* source_pin,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/tclCmdHighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ void TclCmdHighlighter::highlightBlock(const QString& text)
command_data = new TclCmdUserData();
}
command_data->line_continued = true;
command_data->commands = matched_commands;
command_data->commands = std::move(matched_commands);
if (text.size() > 0 && text.at(text.size() - 1).toLatin1() != '\\') {
command_data->line_continued = false;
}
Expand Down
Loading

0 comments on commit 860e03a

Please sign in to comment.