fix potential undefined behaviour

fix #19
This commit is contained in:
Evgeniy A. Dushistov
2017-07-04 22:30:26 +03:00
parent b4fc882f25
commit b2ced870ab
3 changed files with 9 additions and 17 deletions

View File

@@ -157,7 +157,7 @@ int main(int argc, char *argv[]) try {
});
std::list<std::string> order_list;
if (use_dict_list) {
if (use_dict_list != nullptr) {
for (auto &&x : bookname_to_ifo) {
gchar **p = get_impl(use_dict_list);
for (; *p != nullptr; ++p)

View File

@@ -89,7 +89,6 @@ bool DictInfo::load_from_ifo_file(const std::string& ifofilename,
if (!g_str_has_prefix(
g_str_has_prefix(get_impl(buffer), (const gchar *)(utf8_bom)) ? get_impl(buffer) + 3 : get_impl(buffer),
magic_data)) {
g_free(buffer);
return false;
}

View File

@@ -27,6 +27,14 @@ public:
}
}
friend inline bool operator==(const ResourceWrapper& lhs, nullptr_t) noexcept {
return !lhs.p_;
}
friend inline bool operator!=(const ResourceWrapper& lhs, nullptr_t) noexcept {
return !!lhs.p_;
}
friend inline T *get_impl(const ResourceWrapper& rw) {
return rw.p_;
}
@@ -39,21 +47,6 @@ private:
T *p_;
void free_resource() { if (p_) unref_res(p_); }
// Helper for enabling 'if (sp)'
struct Tester {
Tester() {}
private:
void operator delete(void*);
};
public:
// enable 'if (sp)'
operator Tester*() const {
if (!*this)
return 0;
static Tester t;
return &t;
}
};
namespace glib {