1
0
mirror of synced 2024-12-01 10:47:19 +01:00

fix: Random build errors with GCC 12.1.0

This commit is contained in:
WerWolv 2022-05-17 20:46:42 +02:00
parent 5f17d7aa75
commit c4b7d89713
9 changed files with 48 additions and 42 deletions

View File

@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include <hex/helpers/fs.hpp> #include <hex/helpers/fs.hpp>
#include <hex/helpers/file.hpp>
namespace hex { namespace hex {
@ -26,7 +27,7 @@ namespace hex {
[[nodiscard]] bool valid() const { return this->m_valid; } [[nodiscard]] bool valid() const { return this->m_valid; }
private: private:
void parseThingyFile(std::ifstream &content); void parseThingyFile(fs::File &file);
bool m_valid = false; bool m_valid = false;

View File

@ -2,16 +2,13 @@
#include <hex/helpers/utils.hpp> #include <hex/helpers/utils.hpp>
#include <fstream>
namespace hex { namespace hex {
EncodingFile::EncodingFile(Type type, const std::fs::path &path) { EncodingFile::EncodingFile(Type type, const std::fs::path &path) {
std::ifstream encodingFile(path.c_str()); auto file = fs::File(path, fs::File::Mode::Read);
switch (type) { switch (type) {
case Type::Thingy: case Type::Thingy:
parseThingyFile(encodingFile); parseThingyFile(file);
break; break;
default: default:
return; return;
@ -34,22 +31,23 @@ namespace hex {
return { ".", 1 }; return { ".", 1 };
} }
void EncodingFile::parseThingyFile(std::ifstream &content) { void EncodingFile::parseThingyFile(fs::File &file) {
for (std::string line; std::getline(content, line);) { for (const auto &line : splitString(file.readString(), "\n")) {
std::string from, to; std::string from, to;
{ {
auto delimiterPos = line.find('=', 0); auto delimiterPos = line.find('=');
if (delimiterPos == std::string::npos) if (delimiterPos == std::string::npos)
continue; continue;
if (delimiterPos >= from.length())
continue;
if (delimiterPos >= to.length())
continue;
from = line.substr(0, delimiterPos); from = line.substr(0, delimiterPos);
to = line.substr(delimiterPos + 1); to = line.substr(delimiterPos + 1);
hex::trim(from);
hex::trim(to);
if (from.empty()) continue; if (from.empty()) continue;
if (to.empty()) to = " "; if (to.empty()) to = " ";
} }

View File

@ -76,6 +76,11 @@ namespace hex {
} }
static PyObject *createStructureType(const std::string &keyword, PyObject *args) { static PyObject *createStructureType(const std::string &keyword, PyObject *args) {
if (args == nullptr) {
PyErr_BadArgument();
return nullptr;
}
auto type = PyTuple_GetItem(args, 0); auto type = PyTuple_GetItem(args, 0);
if (type == nullptr) { if (type == nullptr) {
PyErr_BadArgument(); PyErr_BadArgument();
@ -119,10 +124,19 @@ namespace hex {
for (Py_ssize_t i = 0; i < PyList_Size(list); i++) { for (Py_ssize_t i = 0; i < PyList_Size(list); i++) {
auto item = PyList_GetItem(list, i); auto item = PyList_GetItem(list, i);
if (item == nullptr) {
PyErr_SetString(PyExc_TypeError, "failed to get item from list");
return nullptr;
}
auto memberName = PyUnicode_AsUTF8(PyTuple_GetItem(item, 0)); auto memberName = PyUnicode_AsUTF8(PyTuple_GetItem(item, 0));
if (memberName == nullptr) {
PyErr_SetString(PyExc_TypeError, "invalid member name");
return nullptr;
}
auto memberType = PyTuple_GetItem(item, 1); auto memberType = PyTuple_GetItem(item, 1);
if (memberType == nullptr) { if (!PyTuple_Check(memberType) || memberType == nullptr) {
PyErr_SetString(PyExc_TypeError, "member needs to have a annotation extending from ImHexType"); PyErr_SetString(PyExc_TypeError, "member needs to have a annotation extending from ImHexType");
return nullptr; return nullptr;
} }
@ -148,12 +162,6 @@ namespace hex {
code += "["s + PyUnicode_AsUTF8(arraySize) + "];\n"; code += "["s + PyUnicode_AsUTF8(arraySize) + "];\n";
else if (PyLong_Check(arraySize)) else if (PyLong_Check(arraySize))
code += "["s + std::to_string(PyLong_AsLong(arraySize)) + "];\n"; code += "["s + std::to_string(PyLong_AsLong(arraySize)) + "];\n";
else {
PyErr_SetString(PyExc_TypeError, "invalid array size type. Expected string or int");
return nullptr;
}
} else { } else {
auto memberTypeInstance = PyObject_CallObject(memberType, nullptr); auto memberTypeInstance = PyObject_CallObject(memberType, nullptr);
if (memberTypeInstance == nullptr || memberTypeInstance->ob_type->tp_base == nullptr || memberTypeInstance->ob_type->tp_base->tp_name != "ImHexType"s) { if (memberTypeInstance == nullptr || memberTypeInstance->ob_type->tp_base == nullptr || memberTypeInstance->ob_type->tp_base->tp_name != "ImHexType"s) {

View File

@ -92,14 +92,16 @@ namespace hex::plugin::builtin {
ImGui::TextUnformatted(binary.c_str()); ImGui::TextUnformatted(binary.c_str());
return binary; return binary;
}; };
}, [](std::string value, std::endian endian) -> std::vector<u8> { }, [](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian); hex::unused(endian);
if (value.starts_with("0b"))
value = value.substr(2); std::string copy = value;
if (copy.starts_with("0b"))
copy = copy.substr(2);
if (value.size() > 8) return { }; if (value.size() > 8) return { };
u8 byte = 0x00; u8 byte = 0x00;
for (char c : value) { for (char c : copy) {
byte <<= 1; byte <<= 1;
if (c == '1') if (c == '1')

View File

@ -226,12 +226,10 @@ namespace hex::plugin::builtin::prv {
} }
std::string GDBProvider::getName() const { std::string GDBProvider::getName() const {
std::string address, port; std::string address = "-";
std::string port = "-";
if (!this->isConnected()) { if (this->isConnected()) {
address = "-";
port = "-";
} else {
address = this->m_ipAddress; address = this->m_ipAddress;
port = std::to_string(this->m_port); port = std::to_string(this->m_port);
} }

View File

@ -425,19 +425,18 @@ namespace hex::plugin::builtin {
ImGui::NewLine(); ImGui::NewLine();
if (evaluate) { if (evaluate) {
std::optional<long double> result;
try { try {
result = mathEvaluator.evaluate(mathInput); auto result = mathEvaluator.evaluate(mathInput);
if (result.has_value()) {
mathHistory.push_back(result.value());
mathInput.clear();
lastMathError.clear();
}
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
lastMathError = e.what(); lastMathError = e.what();
} }
if (result.has_value()) {
mathHistory.push_back(result.value());
mathInput.clear();
lastMathError.clear();
}
} }
} }

View File

@ -7,7 +7,7 @@
namespace hex::plugin::builtin { namespace hex::plugin::builtin {
ViewCommandPalette::ViewCommandPalette() : View("hex.builtin.view.command_palette.name") { ViewCommandPalette::ViewCommandPalette() : View("hex.builtin.view.command_palette.name") {
this->m_commandBuffer.resize(1024, 0x00); this->m_commandBuffer = std::vector<char>(1024, 0x00);
ShortcutManager::addGlobalShortcut(CTRL + SHIFT + Keys::P, [this] { ShortcutManager::addGlobalShortcut(CTRL + SHIFT + Keys::P, [this] {
EventManager::post<RequestOpenPopup>("hex.builtin.view.command_palette.name"_lang); EventManager::post<RequestOpenPopup>("hex.builtin.view.command_palette.name"_lang);

View File

@ -366,7 +366,7 @@ namespace hex::plugin::builtin {
if (ImNodes::IsLinkCreated(&from, &to)) { if (ImNodes::IsLinkCreated(&from, &to)) {
do { do {
dp::Attribute *fromAttr, *toAttr; dp::Attribute *fromAttr = nullptr, *toAttr = nullptr;
for (auto &node : this->m_nodes) { for (auto &node : this->m_nodes) {
for (auto &attribute : node->getAttributes()) { for (auto &attribute : node->getAttributes()) {
if (attribute.getId() == static_cast<u32>(from)) if (attribute.getId() == static_cast<u32>(from))
@ -535,7 +535,7 @@ namespace hex::plugin::builtin {
newLink.setID(linkId); newLink.setID(linkId);
this->m_links.push_back(newLink); this->m_links.push_back(newLink);
dp::Attribute *fromAttr, *toAttr; dp::Attribute *fromAttr = nullptr, *toAttr = nullptr;
for (auto &node : this->m_nodes) { for (auto &node : this->m_nodes) {
for (auto &attribute : node->getAttributes()) { for (auto &attribute : node->getAttributes()) {
if (attribute.getId() == newLink.getFromId()) if (attribute.getId() == newLink.getFromId())

View File

@ -26,8 +26,8 @@ namespace hex::plugin::builtin {
ViewHexEditor::ViewHexEditor() : View("hex.builtin.view.hex_editor.name"_lang) { ViewHexEditor::ViewHexEditor() : View("hex.builtin.view.hex_editor.name"_lang) {
this->m_searchStringBuffer.resize(0xFFF, 0x00); this->m_searchStringBuffer = std::vector<char>(0xFFF, 0x00);
this->m_searchHexBuffer.resize(0xFFF, 0x00); this->m_searchHexBuffer = std::vector<char>(0xFFF, 0x00);
ContentRegistry::FileHandler::add({ ".hexproj" }, [](const auto &path) { ContentRegistry::FileHandler::add({ ".hexproj" }, [](const auto &path) {
return ProjectFile::load(path); return ProjectFile::load(path);