diff --git a/src/core/alloc_type.hpp b/src/core/alloc_type.hpp index 4451f04795..5aa898db6c 100644 --- a/src/core/alloc_type.hpp +++ b/src/core/alloc_type.hpp @@ -163,20 +163,12 @@ public: /** * Memory release for a single class instance. * @param ptr the memory to free. - * @param size the amount of allocated memory (unused). - * - * @warning The value of the \a size parameter can only be trusted for - * classes that have their own (virtual) destructor method. */ FORCEINLINE void operator delete(void *ptr, size_t size) { free(ptr); } /** * Memory release for an array of class instances. * @param ptr the memory to free. - * @param size the amount of allocated memory (unused). - * - * @warning The value of the \a size parameter can only be trusted for - * classes that have their own (virtual) destructor method. */ FORCEINLINE void operator delete[](void *ptr, size_t size) { free(ptr); } }; diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 0e5e620f7a..e766bb4d72 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -51,36 +51,51 @@ enum GRFExtendedLanguages { * but according to a different lang. */ struct GRFText { - public: - static GRFText* New(byte langid, const char* text) - { - return new(strlen(text) + 1) GRFText(langid, text); - } +public: + static GRFText *New(byte langid, const char *text) + { + return new (strlen(text) + 1) GRFText(langid, text); + } - private: - GRFText(byte langid_, const char* text_) : next(NULL), langid(langid_) - { - strcpy(text, text_); - } + /** + * Helper allocation function to disallow something. + * Don't allow simple 'news'; they wouldn't have enough memory. + * @param size the amount of space not to allocate + */ + void *operator new(size_t size) + { + NOT_REACHED(); + } - void *operator new(size_t size, size_t extra) - { - return ::operator new(size + extra); - } + /** + * Free the memory we allocated + * @param p memory to free + */ + void operator delete(void *p) + { + free(p); + } +private: + GRFText(byte langid_, const char *text_) : next(NULL), langid(langid_) + { + strcpy(text, text_); + } + + /** + * Allocate memory for this class. + * @param size the size of the instance + * @param extra the extra memory for the text + * @return the requested amount of memory for both the instance and the text + */ + void *operator new(size_t size, size_t extra) + { + return MallocT(size + extra); + } public: - /* dummy operator delete to silence VC8: - * 'void *GRFText::operator new(size_t,size_t)' : no matching operator delete found; - * memory will not be freed if initialization throws an exception */ - void operator delete(void *p, size_t extra) - { - return ::operator delete(p); - } - - public: - GRFText *next; - byte langid; - char text[VARARRAY_SIZE]; + GRFText *next; + byte langid; + char text[VARARRAY_SIZE]; }; diff --git a/src/stdafx.h b/src/stdafx.h index a0ce63bdd2..f6a08e24c0 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -173,6 +173,7 @@ #if (_MSC_VER < 1400) // MSVC 2005 safety checks #error "Only MSVC 2005 or higher are supported. MSVC 2003 and earlier are not! Upgrade your compiler." #endif /* (_MSC_VER < 1400) */ + #pragma warning(disable: 4291) // no matching operator delete found; memory will not be freed if initialization throws an exception (reason: our overloaded functions never throw an exception) #pragma warning(disable: 4996) // 'strdup' was declared deprecated #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions #pragma warning(disable: 6308) // code analyzer: 'realloc' might return null pointer: assigning null pointer to 't_ptr', which is passed as an argument to 'realloc', will cause the original memory block to be leaked diff --git a/src/window_gui.h b/src/window_gui.h index bc3242d865..5cbff5a3aa 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -139,11 +139,26 @@ public: Window(const WindowDesc *desc, WindowNumber number = 0); virtual ~Window(); - /* Don't allow arrays; arrays of Windows are pointless as you need - * to destruct them all at the same time too, which is kinda hard. */ - FORCEINLINE void *operator new[](size_t size) { NOT_REACHED(); } - /* Don't free the window directly; it corrupts the linked list when iterating */ - FORCEINLINE void operator delete(void *ptr, size_t size) {} + + /** + * Helper allocation function to disallow something. + * Don't allow arrays; arrays of Windows are pointless as you need + * to destruct them all at the same time too, which is kinda hard. + * @param size the amount of space not to allocate + */ + FORCEINLINE void *operator new[](size_t size) + { + NOT_REACHED(); + } + + /** + * Helper allocation function to disallow something. + * Don't free the window directly; it corrupts the linked list when iterating + * @param ptr the pointer not to free + */ + FORCEINLINE void operator delete(void *ptr) + { + } uint16 flags4; ///< Window flags, @see WindowFlags WindowClass window_class; ///< Window class