From 718ab5c5ab201c6c384bc6579dbb615db5d7bc02 Mon Sep 17 00:00:00 2001 From: lgomez Date: Wed, 16 Oct 2024 09:52:06 -0500 Subject: [PATCH] -Use std::optional for symbol encoding --- src/SQLiteDB.cpp | 5 ++--- src/Symbol.cpp | 14 +++++++------- src/Symbol.h | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/SQLiteDB.cpp b/src/SQLiteDB.cpp index 58379fcd..bd6f8e60 100644 --- a/src/SQLiteDB.cpp +++ b/src/SQLiteDB.cpp @@ -1179,7 +1179,7 @@ int SQLiteDB::writeSymbolsToDatabase(ElfFile& inElf) */ std::string writeSymbolQuery{}; - if (!symbol->hasEncoding()) + if (!symbol->getEncoding()) { writeSymbolQuery += "INSERT INTO symbols(elf, name, byte_size, artifact, long_description, short_description) " @@ -1242,8 +1242,7 @@ int SQLiteDB::writeSymbolsToDatabase(ElfFile& inElf) writeSymbolQuery += ","; writeSymbolQuery += "\""; - writeSymbolQuery += std::to_string(symbol->getElf().getDWARFEncoding(symbol->getEncoding()).getId()); - // writeSymbolQuery += "-47"; + writeSymbolQuery += std::to_string(symbol->getElf().getDWARFEncoding(symbol->getEncoding().value()).getId()); writeSymbolQuery += "\","; writeSymbolQuery += std::to_string(symbol->getArtifact().getId()); diff --git a/src/Symbol.cpp b/src/Symbol.cpp index 911754c7..5dad9996 100644 --- a/src/Symbol.cpp +++ b/src/Symbol.cpp @@ -191,31 +191,31 @@ bool Symbol::hasBitFields(void) return hasBitField; } -Artifact& Symbol::getArtifact() { return artifact; } +Artifact& Symbol::getArtifact() { return artifact; } /** * @brief Symbol::setTargetSymbol * @note Might make sense to use std:optional for targetSymbol, however need to upgrade to C++17 first. * @param newTargetSymbol */ -void Symbol::setTargetSymbol(Symbol* newTargetSymbol) { targetSymbol = newTargetSymbol; } +void Symbol::setTargetSymbol(Symbol* newTargetSymbol) { targetSymbol = newTargetSymbol; } /** * @brief Symbol::hasTargetSymbol * If this function returns false, then * that means this is the concrete symbol not a typdef'd(aliased) symbol. */ -bool Symbol::hasTargetSymbol() { return targetSymbol != nullptr; } +bool Symbol::hasTargetSymbol() { return targetSymbol != nullptr; } -Symbol* Symbol::getTargetSymbol() { return targetSymbol; } +Symbol* Symbol::getTargetSymbol() { return targetSymbol; } /** * @brief Symbol::setEncoding * @param newEncoding an integer which is one of the values specified in * in dwarf.h or in DWARF5 specification document section 5.1.1 titled "Base Type Encodings" */ -void Symbol::setEncoding(int newEncoding) { encoding = newEncoding; } +void Symbol::setEncoding(int newEncoding) { encoding = newEncoding; } -bool Symbol::hasEncoding() { return encoding != -1; } +bool Symbol::hasEncoding() { return encoding != -1; } -int Symbol::getEncoding() { return encoding; } +std::optional Symbol::getEncoding() { return encoding; } diff --git a/src/Symbol.h b/src/Symbol.h index 0896a2f2..53246be4 100644 --- a/src/Symbol.h +++ b/src/Symbol.h @@ -71,7 +71,7 @@ class Symbol bool hasEncoding(); - int getEncoding(); + std::optional getEncoding(); private: ElfFile &elf; @@ -87,7 +87,7 @@ class Symbol std::string short_description; std::string long_description; - int encoding{-1}; + std::optional encoding{std::nullopt}; }; #endif /* SYMBOL_H_ */