aboutsummaryrefslogtreecommitdiff
path: root/backend/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/util.cpp')
-rw-r--r--backend/util.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/backend/util.cpp b/backend/util.cpp
index 557df4c..edf9539 100644
--- a/backend/util.cpp
+++ b/backend/util.cpp
@@ -7,35 +7,41 @@
#include "ArmorObject.h"
template <>
-void safe_free(void * & ptr) {
- if (ptr == nullptr) return;
- free(ptr);
- ptr = nullptr;
+void safe_free(void ** ptr) {
+ if (*ptr == nullptr) return;
+ free(*ptr);
+ *ptr = nullptr;
}
template <>
-void safe_free(const char * & ptr) {
- auto x = static_cast<void *>(const_cast<char *>(ptr));
- safe_free(x);
+void safe_free(const char ** ptr) {
+ // wow c++ casts so readable
+ auto a = const_cast<char **>(ptr);
+ auto b = static_cast<void *>(a);
+ auto c = reinterpret_cast<void**>(b);
+ safe_free(c);
}
template <>
-void safe_free(WeaponObject * & ptr) {
- delete ptr;
+void safe_free(WeaponObject ** ptr) {
+ delete *ptr;
+ *ptr = nullptr;
}
template <>
-void safe_free(ArmorObject * & ptr) {
- delete ptr;
+void safe_free(ArmorObject ** ptr) {
+ delete *ptr;
+ *ptr = nullptr;
}
template <typename T>
-void safe_free(T * & ptr) {
- auto x = static_cast<void *>(ptr);
- safe_free(x);
+void safe_free(T ** ptr) {
+ auto a = static_cast<void *>(ptr);
+ auto b = reinterpret_cast<void **>(ptr);
+ safe_free(b);
}
-template void safe_free(char * &);
-template void safe_free(FILE * &);
+template void safe_free(char **);
+template void safe_free(FILE **);