diff --git a/UEFIDump/uefidump.cpp b/UEFIDump/uefidump.cpp index 101e88d..c8daf79 100644 --- a/UEFIDump/uefidump.cpp +++ b/UEFIDump/uefidump.cpp @@ -96,7 +96,7 @@ USTATUS UEFIDumper::dump(const UByteArray & buffer, const UString & inPath, cons std::vector report = ffsReport.generate(); if (report.size()) { std::ofstream ofs; - ofs.open(reportPath, std::ofstream::out); + ofs.open((const char*)reportPath, std::ofstream::out); for (size_t i = 0; i < report.size(); i++) { ofs << (const char*)report[i].toLocal8Bit() << std::endl; } @@ -160,8 +160,8 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index) UByteArray data = model.header(index); if (!data.isEmpty()) { std::ofstream file; - std::string str = std::string((const char*)name) + std::string("_header.bin"); - file.open(str, std::ios::out | std::ios::binary); + UString str = name + UString("_header.bin"); + file.open((const char*)str, std::ios::out | std::ios::binary); file.write(data.constData(), data.size()); file.close(); } @@ -170,8 +170,8 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index) data = model.body(index); if (!data.isEmpty()) { std::ofstream file; - std::string str = std::string((const char*)name) + std::string("_body.bin"); - file.open(str, std::ios::out | std::ios::binary); + UString str = name + UString("_body.bin"); + file.open((const char*)str, std::ios::out | std::ios::binary); file.write(data.constData(), data.size()); file.close(); } @@ -184,8 +184,8 @@ USTATUS UEFIDumper::recursiveDump(const UModelIndex & index) info += model.info(index) + "\n"; std::ofstream file; - std::string str = std::string((const char*)name) + std::string("_info.txt"); - file.open(str, std::ios::out); + UString str = name + UString("_info.txt"); + file.open((const char*)str, std::ios::out); file.write((const char*)info, info.length()); file.close(); diff --git a/common/treeitem.cpp b/common/treeitem.cpp index bf0006d..3081bb9 100644 --- a/common/treeitem.cpp +++ b/common/treeitem.cpp @@ -45,8 +45,8 @@ TreeItem::~TreeItem() { UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem) { - std::list::iterator found = std::find(std::begin(childItems), std::end(childItems), item); - if (found == std::end(childItems)) + std::list::iterator found = std::find(childItems.begin(), childItems.end(), item); + if (found == childItems.end()) return U_ITEM_NOT_FOUND; childItems.insert(found, newItem); return U_SUCCESS; @@ -54,8 +54,8 @@ UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem) UINT8 TreeItem::insertChildAfter(TreeItem *item, TreeItem *newItem) { - std::list::iterator found = std::find(std::begin(childItems), std::end(childItems), item); - if (found == std::end(childItems)) + std::list::iterator found = std::find(childItems.begin(), childItems.end(), item); + if (found == childItems.end()) return U_ITEM_NOT_FOUND; childItems.insert(++found, newItem); return U_SUCCESS; @@ -83,7 +83,7 @@ UString TreeItem::data(int column) const int TreeItem::row() const { if (parentItem) { - std::list::const_iterator iter = parentItem->childItems.cbegin(); + std::list::const_iterator iter = parentItem->childItems.begin(); for (int i = 0; i < (int)parentItem->childItems.size(); ++i, ++iter) { if (const_cast(this) == *iter) return i; diff --git a/common/treeitem.h b/common/treeitem.h index ec81b37..b28d076 100644 --- a/common/treeitem.h +++ b/common/treeitem.h @@ -15,11 +15,22 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define TREEITEM_H #include +#include #include "ubytearray.h" #include "ustring.h" #include "basetypes.h" +template +ForwardIt u_std_next( + ForwardIt it, + typename std::iterator_traits::difference_type n = 1 +) +{ + std::advance(it, n); + return it; +} + class TreeItem { public: @@ -36,7 +47,7 @@ public: UINT8 insertChildAfter(TreeItem *item, TreeItem *newItem); // Non-trivial implementation in CPP file // Model support operations - TreeItem *child(int row) { return *std::next(childItems.begin(), row); } + TreeItem *child(int row) { return *u_std_next(childItems.begin(), row); } int childCount() const {return childItems.size(); } int columnCount() const { return 5; } UString data(int column) const; // Non-trivial implementation in CPP file diff --git a/common/ubytearray.h b/common/ubytearray.h index 174c3de..82a6ff3 100644 --- a/common/ubytearray.h +++ b/common/ubytearray.h @@ -36,13 +36,13 @@ public: bool isEmpty() const { return d.length() == 0; } - char* data() { return &(d.front()); /* Feels dirty, but works for all basic_string implementations I know, is fully OK in C++11 and later*/ } + char* data() { return d.length() == 0 ? NULL : &(d.at(0)); /* Feels dirty, but works for all basic_string implementations I know, is fully OK in C++11 and later*/ } const char* data() const { return d.c_str(); } const char* constData() const { return d.c_str(); } void clear() { d.clear(); } int32_t size() const { return d.size(); } - int32_t count(char ch) const { return std::count(d.cbegin(), d.cend(), ch); } + int32_t count(char ch) const { return std::count(d.begin(), d.end(), ch); } char at(uint32_t i) const { return d.at(i); } char operator[](uint32_t i) const { return d[i]; } char& operator[](uint32_t i) { return d[i]; } @@ -61,7 +61,7 @@ public: bool operator!= (const UByteArray & ba) const { return d != ba.d; } inline void swap(UByteArray &other) { std::swap(d, other.d); } UByteArray toHex() { - std::basic_string hex(size() * 2, '\x00'); + std::basic_string hex(size() * 2, '\x00'); for (int32_t i = 0; i < size(); i++) { uint8_t low = d[i] & 0x0F; uint8_t high = (d[i] & 0xF0) >> 4;