Skip to content

Commit

Permalink
more [[nodiscard]]
Browse files Browse the repository at this point in the history
&value[0] -> value.data()
const& -> value + move
  • Loading branch information
eteran committed Mar 19, 2024
1 parent 260cf1b commit 8c1b48a
Show file tree
Hide file tree
Showing 27 changed files with 90 additions and 82 deletions.
2 changes: 1 addition & 1 deletion include/GraphNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GraphNode final : public QGraphicsItem {
public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
QRectF boundingRect() const override;
[[nodiscard]] QRectF boundingRect() const override;

protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *e) override;
Expand Down
24 changes: 12 additions & 12 deletions include/ISymbolManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ class ISymbolManager {
virtual ~ISymbolManager() = default;

public:
[[nodiscard]] virtual const std::shared_ptr<Symbol> find(const QString &name) const = 0;
[[nodiscard]] virtual const std::shared_ptr<Symbol> find(edb::address_t address) const = 0;
[[nodiscard]] virtual const std::shared_ptr<Symbol> findNearSymbol(edb::address_t address) const = 0;
[[nodiscard]] virtual const std::vector<std::shared_ptr<Symbol>> symbols() const = 0;
[[nodiscard]] virtual QHash<edb::address_t, QString> labels() const = 0;
[[nodiscard]] virtual QStringList files() const = 0;
virtual QString findAddressName(edb::address_t address, bool prefixed = true) = 0;
virtual void addSymbol(const std::shared_ptr<Symbol> &symbol) = 0;
virtual void clear() = 0;
virtual void loadSymbolFile(const QString &filename, edb::address_t base) = 0;
virtual void setLabel(edb::address_t address, const QString &label) = 0;
virtual void setSymbolGenerator(ISymbolGenerator *generator) = 0;
[[nodiscard]] virtual QHash<edb::address_t, QString> labels() const = 0;
[[nodiscard]] virtual QString findAddressName(edb::address_t address, bool prefixed = true) = 0;
[[nodiscard]] virtual QStringList files() const = 0;
[[nodiscard]] virtual std::shared_ptr<Symbol> find(const QString &name) const = 0;
[[nodiscard]] virtual std::shared_ptr<Symbol> find(edb::address_t address) const = 0;
[[nodiscard]] virtual std::shared_ptr<Symbol> findNearSymbol(edb::address_t address) const = 0;
[[nodiscard]] virtual std::vector<std::shared_ptr<Symbol>> symbols() const = 0;
virtual void addSymbol(const std::shared_ptr<Symbol> &symbol) = 0;
virtual void clear() = 0;
virtual void loadSymbolFile(const QString &filename, edb::address_t base) = 0;
virtual void setLabel(edb::address_t address, const QString &label) = 0;
virtual void setSymbolGenerator(ISymbolGenerator *generator) = 0;
};

#endif
4 changes: 2 additions & 2 deletions include/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class EDB_EXPORT Status {
Status(OkType) {
}

explicit Status(const QString &message)
: error_(message) {
explicit Status(QString message)
: error_(std::move(message)) {
}

Status(const Status &) = default;
Expand Down
2 changes: 1 addition & 1 deletion plugins/Analyzer/Analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ void Analyzer::collectFuzzyFunctions(RegionData *data) {

QHash<edb::address_t, int> fuzzy_functions;

uint8_t *const first = &data->memory[0];
uint8_t *const first = (data->memory).data();
uint8_t *const last = &first[data->memory.size()];

uint8_t *p = first;
Expand Down
12 changes: 6 additions & 6 deletions plugins/Analyzer/Analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ class Analyzer final : public QObject, public IAnalyzer, public IPlugin {
[[nodiscard]] QWidget *optionsPage() override;

public:
AddressCategory category(edb::address_t address) const override;
FunctionMap functions(const std::shared_ptr<IRegion> &region) const override;
FunctionMap functions() const override;
QSet<edb::address_t> specifiedFunctions() const override { return specifiedFunctions_; }
Result<edb::address_t, QString> findContainingFunction(edb::address_t address) const override;
[[nodiscard]] AddressCategory category(edb::address_t address) const override;
[[nodiscard]] FunctionMap functions() const override;
[[nodiscard]] FunctionMap functions(const std::shared_ptr<IRegion> &region) const override;
[[nodiscard]] QSet<edb::address_t> specifiedFunctions() const override { return specifiedFunctions_; }
[[nodiscard]] Result<edb::address_t, QString> findContainingFunction(edb::address_t address) const override;
bool forFuncsInRange(edb::address_t start, edb::address_t end, std::function<bool(const Function *)> functor) const override;
void analyze(const std::shared_ptr<IRegion> &region) override;
void invalidateAnalysis() override;
void invalidateAnalysis(const std::shared_ptr<IRegion> &region) override;
bool forFuncsInRange(edb::address_t start, edb::address_t end, std::function<bool(const Function *)> functor) const override;

private:
[[nodiscard]] bool findContainingFunction(edb::address_t address, Function *function) const;
Expand Down
4 changes: 2 additions & 2 deletions plugins/BinarySearcher/DialogAsciiString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void DialogAsciiString::doFind() {
edb::address_t stack_address;

if (process->readBytes(stack_ptr, &stack_address, edb::v1::pointer_size())) {
if (process->readBytes(stack_address, &chars[0], chars.size())) {
if (std::memcmp(&chars[0], b.constData(), chars.size()) == 0) {
if (process->readBytes(stack_address, chars.data(), chars.size())) {
if (std::memcmp(chars.data(), b.constData(), chars.size()) == 0) {
results->addResult(DialogResults::RegionType::Stack, stack_ptr);
}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/BinarySearcher/DialogBinaryString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ void DialogBinaryString::doFind() {
while (p < pages_end) {
// compare values..
if (std::memcmp(p, b.constData(), sz) == 0) {
const edb::address_t addr = p - &pages[0] + region->start() + (current_page * page_size);
const edb::address_t addr = p - pages.data() + region->start() + (current_page * page_size);
results_->addResult(DialogResults::RegionType::Data, addr);
}

// update progress bar every 64KB
if ((reinterpret_cast<uint64_t>(p) & 0xFFFF) == 0) {
ui.progressBar->setValue(util::percentage(i, regions.size(), p - &pages[0], region_size));
ui.progressBar->setValue(util::percentage(i, regions.size(), p - pages.data(), region_size));
}

p += align;
Expand Down
4 changes: 2 additions & 2 deletions plugins/DebuggerCore/arch/x86-generic/Breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool Breakpoint::enable() {
if (!enabled()) {
if (IProcess *process = edb::v1::debugger_core->process()) {
std::vector<uint8_t> prev(2);
if (process->readBytes(address(), &prev[0], prev.size())) {
if (process->readBytes(address(), prev.data(), prev.size())) {
originalBytes_ = prev;
const std::vector<uint8_t> *bpBytes = nullptr;

Expand Down Expand Up @@ -178,7 +178,7 @@ bool Breakpoint::enable() {
bool Breakpoint::disable() {
if (enabled()) {
if (IProcess *process = edb::v1::debugger_core->process()) {
if (process->writeBytes(address(), &originalBytes_[0], originalBytes_.size())) {
if (process->writeBytes(address(), originalBytes_.data(), originalBytes_.size())) {
enabled_ = false;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/arch/x86-generic/Breakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Breakpoint final : public IBreakpoint {
[[nodiscard]] bool oneTime() const override { return oneTime_; }
[[nodiscard]] bool internal() const override { return internal_; }
[[nodiscard]] size_t size() const override { return originalBytes_.size(); }
[[nodiscard]] const uint8_t *originalBytes() const override { return &originalBytes_[0]; }
[[nodiscard]] const uint8_t *originalBytes() const override { return originalBytes_.data(); }
[[nodiscard]] IBreakpoint::TypeId type() const override { return type_; }

[[nodiscard]] static std::vector<BreakpointType> supportedTypes();
Expand Down
2 changes: 1 addition & 1 deletion plugins/DebuggerCore/unix/linux/PlatformCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int get_user_stat(const char *path, struct user_stat *user_stat) {
&user_stat->exit_code);

// fill in the pid
r += sscanf(&line[0], "%d", &user_stat->pid);
r += sscanf(line.data(), "%d", &user_stat->pid);

// fill in the comm field
const size_t len = std::min(sizeof(user_stat->comm), (right - left) - 1);
Expand Down
2 changes: 1 addition & 1 deletion plugins/InstructionInspector/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ InstructionDialog::InstructionDialog(QWidget *parent, Qt::WindowFlags f)

if (!insn) {
add({"Bad instruction", "Failed to disassemble instruction at address " + edb::v1::format_pointer(address_)});
add({"Bytes", printBytes(&insnBytes_[0], insnBytes_.size()).c_str()});
add({"Bytes", printBytes(insnBytes_.data(), insnBytes_.size()).c_str()});
} else {
add({"Address", toHex(insn->address).c_str()});
add({"Bytes", printBytes(insn->bytes, insn->size).c_str()});
Expand Down
4 changes: 2 additions & 2 deletions plugins/ODbgRegisterView/BitFieldDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace ODbgRegisterView {

BitFieldDescription::BitFieldDescription(int textWidth, const std::vector<QString> &valueNames, const std::vector<QString> &setValueTexts, const std::function<bool(unsigned, unsigned)> &valueEqualComparator)
: textWidth(textWidth), valueNames(valueNames), setValueTexts(setValueTexts), valueEqualComparator(valueEqualComparator) {
BitFieldDescription::BitFieldDescription(int textWidth, std::vector<QString> valueNames, std::vector<QString> setValueTexts, std::function<bool(unsigned, unsigned)> valueEqualComparator)
: textWidth(textWidth), valueNames(std::move(valueNames)), setValueTexts(std::move(setValueTexts)), valueEqualComparator(std::move(valueEqualComparator)) {
}

}
5 changes: 4 additions & 1 deletion plugins/ODbgRegisterView/BitFieldDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ struct BitFieldDescription {
std::function<bool(unsigned, unsigned)> const valueEqualComparator;

BitFieldDescription(
int textWidth, const std::vector<QString> &valueNames, const std::vector<QString> &setValueTexts, const std::function<bool(unsigned, unsigned)> &valueEqualComparator = [](unsigned a, unsigned b) { return a == b; });
int textWidth,
std::vector<QString> valueNames,
std::vector<QString> setValueTexts,
std::function<bool(unsigned, unsigned)> valueEqualComparator = [](unsigned a, unsigned b) { return a == b; });
};

}
Expand Down
2 changes: 1 addition & 1 deletion plugins/ODbgRegisterView/DialogEditSimdRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class DialogEditSimdRegister : public QDialog {
explicit DialogEditSimdRegister(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
void setValue(const Register &value);
void set_current_element(RegisterViewModelBase::Model::ElementSize size, NumberDisplayMode format, int elementIndex);
Register value() const;
[[nodiscard]] Register value() const;

protected:
bool eventFilter(QObject *, QEvent *) override;
Expand Down
8 changes: 4 additions & 4 deletions plugins/References/DialogReferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ void DialogReferences::doFind() {
const QVector<uint8_t> pages = edb::v1::read_pages(region->start(), page_count);

if (!pages.isEmpty()) {
const uint8_t *p = &pages[0];
const uint8_t *const pages_end = &pages[0] + region->size();
const uint8_t *p = pages.data();
const uint8_t *const pages_end = pages.data() + region->size();

while (p != pages_end) {

if (pages_end - p < static_cast<int>(edb::v1::pointer_size())) {
break;
}

const edb::address_t addr = p - &pages[0] + region->start();
const edb::address_t addr = p - pages.data() + region->start();

edb::address_t test_address(0);
memcpy(&test_address, p, edb::v1::pointer_size());
Expand Down Expand Up @@ -156,7 +156,7 @@ void DialogReferences::doFind() {
}
}

Q_EMIT updateProgress(util::percentage(i, regions.size(), p - &pages[0], region->size()));
Q_EMIT updateProgress(util::percentage(i, regions.size(), p - pages.data(), region->size()));
++p;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ByteShiftArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ uint8_t ByteShiftArray::operator[](std::size_t i) const {
// Desc: returns a read only pointer to the data this byte array holds
//------------------------------------------------------------------------------
const uint8_t *ByteShiftArray::data() const {
return &data_[0];
return data_.data();
}

//------------------------------------------------------------------------------
Expand Down
22 changes: 13 additions & 9 deletions src/CommentServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ Result<QString, QString> CommentServer::resolveFunctionCall(edb::address_t addre

if (!symname.isEmpty()) {
return tr("return to %1 <%2>").arg(edb::v1::format_pointer(address), symname);
} else {
return tr("return to %1").arg(edb::v1::format_pointer(address));
}

return tr("return to %1").arg(edb::v1::format_pointer(address));
}
}
}
Expand All @@ -99,7 +99,9 @@ Result<QString, QString> CommentServer::resolveString(edb::address_t address) co

if (edb::v1::get_ascii_string_at_address(address, temp, min_string_length, MaxStringLength, stringLen)) {
return tr("ASCII \"%1\"").arg(temp);
} else if (edb::v1::get_utf16_string_at_address(address, temp, min_string_length, MaxStringLength, stringLen)) {
}

if (edb::v1::get_utf16_string_at_address(address, temp, min_string_length, MaxStringLength, stringLen)) {
return tr("UTF16 \"%1\"").arg(temp);
}

Expand All @@ -124,12 +126,14 @@ QString CommentServer::comment(edb::address_t address, int size) const {
auto it = customComments_.find(value);
if (it != customComments_.end()) {
return it.value();
} else {
if (Result<QString, QString> ret = resolveFunctionCall(value)) {
return *ret;
} else if (Result<QString, QString> ret = resolveString(value)) {
return *ret;
}
}

if (Result<QString, QString> ret = resolveFunctionCall(value)) {
return *ret;
}

if (Result<QString, QString> ret = resolveString(value)) {
return *ret;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ QDataStream &operator>>(QDataStream &s, IBreakpoint::TypeId &id) {
// Name: getDefaultPluginPath
// Desc: return default path for plugins
//------------------------------------------------------------------------------
static QString getDefaultPluginPath() {
QString getDefaultPluginPath() {
#ifdef DEFAULT_PLUGIN_PATH
const QString default_plugin_path = DEFAULT_PLUGIN_PATH;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private Q_SLOTS:

private Q_SLOTS:
// the manually connected Register slots
QList<QAction *> currentRegisterContextMenuItems() const;
[[nodiscard]] QList<QAction *> currentRegisterContextMenuItems() const;
void mnuRegisterFollowInDump() { followRegisterInDump(false); }
void mnuRegisterFollowInDumpNewTab() { followRegisterInDump(true); }
void mnuRegisterFollowInStack();
Expand Down
8 changes: 3 additions & 5 deletions src/DialogBreakpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "MemoryRegions.h"
#include "edb.h"

#include <QHeaderView>
#include <QInputDialog>
#include <QMessageBox>

#include <QDir>
#include <QFile>
#include <QFileDialog>
#include <QHeaderView>
#include <QInputDialog>
#include <QMessageBox>
#include <QStringList>
#include <QTextStream>
Expand Down Expand Up @@ -254,7 +252,7 @@ void DialogBreakpoints::on_btnImport_clicked() {
}

// Report any errors to the user
if (errors.size() > 0) {
if (!errors.empty()) {
QMessageBox::warning(this, tr("Invalid Breakpoints"), tr("The following breakpoints were not made:\n%1").arg(errors.join("")));
}

Expand Down
20 changes: 12 additions & 8 deletions src/FloatX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,24 @@ FloatValueClass ieee_classify(FloatHolder value) {
if (exponent == ExpMax) {
if (mantissa == 0u) {
return FloatValueClass::Infinity; // |S|11..11|00..00|
} else if (mantissa & QNaN_mask) {
}

if (mantissa & QNaN_mask) {
return FloatValueClass::QNaN; // |S|11..11|1XX..XX|
} else {
return FloatValueClass::SNaN; // |S|11..11|0XX..XX|
}
} else if (exponent == 0u) {

return FloatValueClass::SNaN; // |S|11..11|0XX..XX|
}

if (exponent == 0u) {
if (mantissa == 0u) {
return FloatValueClass::Zero; // |S|00..00|00..00|
} else {
return FloatValueClass::Denormal; // |S|00..00|XX..XX|
}
} else {
return FloatValueClass::Normal;

return FloatValueClass::Denormal; // |S|00..00|XX..XX|
}

return FloatValueClass::Normal;
}

#if defined(HAVE_GDTOA)
Expand Down
2 changes: 1 addition & 1 deletion src/RegisterViewModelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ template <typename UnderlyingType>
BitFieldItem<UnderlyingType>::BitFieldItem(const BitFieldDescriptionEx &descr)
: RegisterViewItem(descr.name), offset_(descr.offset), length_(descr.length), explanations(descr.explanations) {
Q_ASSERT(8 * sizeof(UnderlyingType) >= length_);
Q_ASSERT(explanations.size() == 0 || explanations.size() == 2u << (length_ - 1));
Q_ASSERT(explanations.empty() || explanations.size() == 2u << (length_ - 1));
}

template <typename UnderlyingType>
Expand Down
8 changes: 4 additions & 4 deletions src/SymbolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void SymbolManager::loadSymbolFile(const QString &filename, edb::address_t base)
// Name: find
// Desc:
//------------------------------------------------------------------------------
const std::shared_ptr<Symbol> SymbolManager::find(const QString &name) const {
std::shared_ptr<Symbol> SymbolManager::find(const QString &name) const {

auto it = symbolsByName_.find(name);
if (it != symbolsByName_.end()) {
Expand All @@ -118,7 +118,7 @@ const std::shared_ptr<Symbol> SymbolManager::find(const QString &name) const {
// Name: find
// Desc:
//------------------------------------------------------------------------------
const std::shared_ptr<Symbol> SymbolManager::find(edb::address_t address) const {
std::shared_ptr<Symbol> SymbolManager::find(edb::address_t address) const {
auto it = symbolsByAddress_.find(address);
return (it != symbolsByAddress_.end()) ? it.value() : nullptr;
}
Expand All @@ -127,7 +127,7 @@ const std::shared_ptr<Symbol> SymbolManager::find(edb::address_t address) const
// Name: findNearSymbol
// Desc:
//------------------------------------------------------------------------------
const std::shared_ptr<Symbol> SymbolManager::findNearSymbol(edb::address_t address) const {
std::shared_ptr<Symbol> SymbolManager::findNearSymbol(edb::address_t address) const {

auto it = symbolsByAddress_.lowerBound(address);
if (it != symbolsByAddress_.end()) {
Expand Down Expand Up @@ -264,7 +264,7 @@ bool SymbolManager::processSymbolFile(const QString &f, edb::address_t base, con
// Name: symbols
// Desc:
//------------------------------------------------------------------------------
const std::vector<std::shared_ptr<Symbol>> SymbolManager::symbols() const {
std::vector<std::shared_ptr<Symbol>> SymbolManager::symbols() const {
return symbols_;
}

Expand Down
Loading

0 comments on commit 8c1b48a

Please sign in to comment.