diff options
author | rubidium <rubidium@openttd.org> | 2011-11-12 13:00:29 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-11-12 13:00:29 +0000 |
commit | 7fd1e1df81c3ed45e176f1bbf46d873b6cff316e (patch) | |
tree | 8f2ad83400a7897a066ff4f500bd0cdd150c1b93 /src | |
parent | d61b90ac6fb63ee42f47ca53cacd5aa7d7b30bae (diff) | |
download | openttd-7fd1e1df81c3ed45e176f1bbf46d873b6cff316e.tar.xz |
(svn r23198) -Codechange: introduce a free that takes const pointers so we don't need to cast to void/non-const before being able to free
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/ai_config.cpp | 8 | ||||
-rw-r--r-- | src/ai/ai_info.cpp | 8 | ||||
-rw-r--r-- | src/ai/ai_scanner.cpp | 6 | ||||
-rw-r--r-- | src/ai/api/ai_controller.cpp | 4 | ||||
-rw-r--r-- | src/base_media_base.h | 10 | ||||
-rw-r--r-- | src/blitter/32bpp_optimized.cpp | 2 | ||||
-rw-r--r-- | src/blitter/factory.hpp | 2 | ||||
-rw-r--r-- | src/depend/depend.cpp | 27 | ||||
-rw-r--r-- | src/driver.cpp | 4 | ||||
-rw-r--r-- | src/fileio.cpp | 2 | ||||
-rw-r--r-- | src/network/core/tcp_http.cpp | 2 | ||||
-rw-r--r-- | src/network/core/tcp_http.h | 4 | ||||
-rw-r--r-- | src/newgrf.cpp | 14 | ||||
-rw-r--r-- | src/newgrf_commons.h | 4 | ||||
-rw-r--r-- | src/newgrf_spritegroup.cpp | 6 | ||||
-rw-r--r-- | src/openttd.cpp | 6 | ||||
-rw-r--r-- | src/querystring_gui.h | 2 | ||||
-rw-r--r-- | src/script/script_info.cpp | 14 | ||||
-rw-r--r-- | src/settings_gui.cpp | 2 | ||||
-rw-r--r-- | src/stdafx.h | 9 | ||||
-rw-r--r-- | src/tar_type.h | 2 |
21 files changed, 78 insertions, 60 deletions
diff --git a/src/ai/ai_config.cpp b/src/ai/ai_config.cpp index a00cf4867..a5d656911 100644 --- a/src/ai/ai_config.cpp +++ b/src/ai/ai_config.cpp @@ -17,7 +17,7 @@ void AIConfig::ChangeAI(const char *name, int version, bool force_exact_match, bool is_random_ai) { - free((void *)this->name); + free(this->name); this->name = (name == NULL) ? NULL : strdup(name); this->info = (name == NULL) ? NULL : AI::FindInfo(this->name, version, force_exact_match); this->version = (info == NULL) ? -1 : info->GetVersion(); @@ -31,7 +31,7 @@ void AIConfig::ChangeAI(const char *name, int version, bool force_exact_match, b int start_date = this->GetSetting("start_date"); for (SettingValueList::iterator it = this->settings.begin(); it != this->settings.end(); it++) { - free((void*)(*it).first); + free((*it).first); } this->settings.clear(); @@ -65,7 +65,7 @@ AIConfig::AIConfig(const AIConfig *config) AIConfig::~AIConfig() { - free((void *)this->name); + free(this->name); this->ResetSettings(); if (this->config_list != NULL) delete this->config_list; } @@ -148,7 +148,7 @@ void AIConfig::SetSetting(const char *name, int value) void AIConfig::ResetSettings() { for (SettingValueList::iterator it = this->settings.begin(); it != this->settings.end(); it++) { - free((void*)(*it).first); + free((*it).first); } this->settings.clear(); } diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp index a1d635ac0..630f04b82 100644 --- a/src/ai/ai_info.cpp +++ b/src/ai/ai_info.cpp @@ -39,7 +39,7 @@ AIConfigItem _start_date_config = { AILibrary::~AILibrary() { - free((void *)this->category); + free(this->category); } /* static */ SQInteger AIFileInfo::Constructor(HSQUIRRELVM vm, AIFileInfo *info) @@ -146,8 +146,8 @@ AIInfo::~AIInfo() { /* Free all allocated strings */ for (AIConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) { - free((void*)(*it).name); - free((void*)(*it).description); + free((*it).name); + free((*it).description); if (it->labels != NULL) { for (LabelMapping::iterator it2 = (*it).labels->Begin(); it2 != (*it).labels->End(); it2++) { free(it2->second); @@ -156,7 +156,7 @@ AIInfo::~AIInfo() } } this->config_list.clear(); - free((void*)this->api_version); + free(this->api_version); } bool AIInfo::CanLoadFromVersion(int version) const diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp index 9e752c010..a3995c01a 100644 --- a/src/ai/ai_scanner.cpp +++ b/src/ai/ai_scanner.cpp @@ -68,16 +68,16 @@ void AIScanner::Reset() { AIInfoList::iterator it = this->info_list.begin(); for (; it != this->info_list.end(); it++) { - free((void *)(*it).first); + free((*it).first); delete (*it).second; } it = this->info_single_list.begin(); for (; it != this->info_single_list.end(); it++) { - free((void *)(*it).first); + free((*it).first); } AILibraryList::iterator lit = this->library_list.begin(); for (; lit != this->library_list.end(); lit++) { - free((void *)(*lit).first); + free((*lit).first); delete (*lit).second; } diff --git a/src/ai/api/ai_controller.cpp b/src/ai/api/ai_controller.cpp index c6130303d..0c478cf4a 100644 --- a/src/ai/api/ai_controller.cpp +++ b/src/ai/api/ai_controller.cpp @@ -54,8 +54,8 @@ AIController::AIController() : AIController::~AIController() { for (LoadedLibraryList::iterator iter = this->loaded_library.begin(); iter != this->loaded_library.end(); iter++) { - free((void *)(*iter).second); - free((void *)(*iter).first); + free((*iter).second); + free((*iter).first); } this->loaded_library.clear(); diff --git a/src/base_media_base.h b/src/base_media_base.h index f026e4b1e..c6c0fd13e 100644 --- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -70,16 +70,16 @@ struct BaseSet { /** Free everything we allocated */ ~BaseSet() { - free((void*)this->name); + free(this->name); for (TranslatedStrings::iterator iter = this->description.Begin(); iter != this->description.End(); iter++) { - free((void*)iter->first); - free((void*)iter->second); + free(iter->first); + free(iter->second); } for (uint i = 0; i < NUM_FILES; i++) { - free((void*)this->files[i].filename); - free((void*)this->files[i].missing_warning); + free(this->files[i].filename); + free(this->files[i].missing_warning); } delete this->next; diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp index acbf91b0f..8449fb154 100644 --- a/src/blitter/32bpp_optimized.cpp +++ b/src/blitter/32bpp_optimized.cpp @@ -354,7 +354,7 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr lengths[z][1] = (byte *)dst_n_ln - (byte *)dst_n_orig[z]; free(src_orig->data); - free((void *)src_orig); + free(src_orig); } uint len = 0; // total length of data diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp index 956b39c9d..e480459cc 100644 --- a/src/blitter/factory.hpp +++ b/src/blitter/factory.hpp @@ -78,7 +78,7 @@ public: if (this->name == NULL) return; GetBlitters().erase(this->name); if (GetBlitters().empty()) delete &GetBlitters(); - free((void *)this->name); + free(this->name); } /** diff --git a/src/depend/depend.cpp b/src/depend/depend.cpp index c224efdaf..b9c8f7a23 100644 --- a/src/depend/depend.cpp +++ b/src/depend/depend.cpp @@ -30,6 +30,15 @@ #include <set> #include <stack> +/** + * Version of the standard free that accepts const pointers. + * @param ptr The data to free. + */ +static inline void free(const void *ptr) +{ + free(const_cast<void *>(ptr)); +} + #ifndef PATH_MAX /** The maximum length of paths, if we don't know it. */ # define PATH_MAX 260 @@ -672,7 +681,7 @@ void ScanFile(const char *filename, const char *ext, bool header, bool verbose) } } if (curfile->second->find(h) == curfile->second->end()) curfile->second->insert(strdup(h)); - free((void*)h); + free(h); } } /* FALL THROUGH */ @@ -705,7 +714,7 @@ void ScanFile(const char *filename, const char *ext, bool header, bool verbose) } StringSet::iterator it = defines.find(lexer.GetString()); if (it != defines.end()) { - free((void*)*it); + free(*it); defines.erase(it); } lexer.Lex(); @@ -808,7 +817,7 @@ void ScanFile(const char *filename, const char *ext, bool header, bool verbose) if (!header) { for (StringSet::iterator it = defines.begin(); it != defines.end(); it++) { - free((void*)*it); + free(*it); } defines.clear(); while (!ignore.empty()) ignore.pop(); @@ -940,31 +949,31 @@ int main(int argc, char *argv[]) for (StringMap::iterator it = _files.begin(); it != _files.end(); it++) { for (StringSet::iterator h = it->second->begin(); h != it->second->end(); h++) { - free((void*)*h); + free(*h); } it->second->clear(); delete it->second; - free((void*)it->first); + free(it->first); } _files.clear(); for (StringMap::iterator it = _headers.begin(); it != _headers.end(); it++) { for (StringSet::iterator h = it->second->begin(); h != it->second->end(); h++) { - free((void*)*h); + free(*h); } it->second->clear(); delete it->second; - free((void*)it->first); + free(it->first); } _headers.clear(); for (StringSet::iterator it = _defines.begin(); it != _defines.end(); it++) { - free((void*)*it); + free(*it); } _defines.clear(); for (StringSet::iterator it = _include_dirs.begin(); it != _include_dirs.end(); it++) { - free((void*)*it); + free(*it); } _include_dirs.clear(); diff --git a/src/driver.cpp b/src/driver.cpp index 8ff3e361b..6419cdd4c 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -236,8 +236,8 @@ DriverFactoryBase::~DriverFactoryBase() const char *longname = (*it).first; GetDrivers().erase(it); - free((void *)longname); + free(longname); if (GetDrivers().empty()) delete &GetDrivers(); - free((void *)this->name); + free(this->name); } diff --git a/src/fileio.cpp b/src/fileio.cpp index dbf0bc01b..43d1d4d8b 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -1175,7 +1175,7 @@ void DeterminePaths(const char *exe) /* If we don't have networking, we don't need to make the directory. But * if it exists we keep it, otherwise remove it from the search paths. */ if (!FileExists(_searchpaths[SP_AUTODOWNLOAD_DIR])) { - free((void*)_searchpaths[SP_AUTODOWNLOAD_DIR]); + free(_searchpaths[SP_AUTODOWNLOAD_DIR]); _searchpaths[SP_AUTODOWNLOAD_DIR] = NULL; } #endif /* ENABLE_NETWORK */ diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp index 0bf733462..386ba776c 100644 --- a/src/network/core/tcp_http.cpp +++ b/src/network/core/tcp_http.cpp @@ -73,7 +73,7 @@ NetworkHTTPSocketHandler::~NetworkHTTPSocketHandler() if (this->sock != INVALID_SOCKET) closesocket(this->sock); this->sock = INVALID_SOCKET; - free((void*)this->data); + free(this->data); } NetworkRecvStatus NetworkHTTPSocketHandler::CloseConnection(bool error) diff --git a/src/network/core/tcp_http.h b/src/network/core/tcp_http.h index 1af7c31df..dc678cca0 100644 --- a/src/network/core/tcp_http.h +++ b/src/network/core/tcp_http.h @@ -105,13 +105,13 @@ public: /** Free all our allocated data. */ ~NetworkHTTPContentConnecter() { - free((void*)this->url); + free(this->url); } virtual void OnFailure() { this->callback->OnFailure(); - free((void*)this->data); + free(this->data); } virtual void OnConnect(SOCKET s) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 41bbc07a6..2afd74686 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3071,10 +3071,10 @@ static void CleanIndustryTileTable(IndustrySpec *ind) if (HasBit(ind->cleanup_flag, CLEAN_TILELAYOUT) && ind->table != NULL) { for (int j = 0; j < ind->num_table; j++) { /* remove the individual layouts */ - free((void*)ind->table[j]); + free(ind->table[j]); } /* remove the layouts pointers */ - free((void*)ind->table); + free(ind->table); ind->table = NULL; } } @@ -3322,7 +3322,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, } if (HasBit(indsp->cleanup_flag, CLEAN_RANDOMSOUNDS)) { - free((void*)indsp->random_sounds); + free(indsp->random_sounds); } indsp->random_sounds = sounds; SetBit(indsp->cleanup_flag, CLEAN_RANDOMSOUNDS); @@ -7663,10 +7663,10 @@ static void ResetCustomAirports() /* We need to remove the tiles layouts */ for (int j = 0; j < as->num_table; j++) { /* remove the individual layouts */ - free((void*)as->table[j]); + free(as->table[j]); } - free((void*)as->table); - free((void*)as->depot_table); + free(as->table); + free(as->depot_table); free(as); } @@ -7703,7 +7703,7 @@ static void ResetCustomIndustries() /* We need to remove the sounds array */ if (HasBit(ind->cleanup_flag, CLEAN_RANDOMSOUNDS)) { - free((void*)ind->random_sounds); + free(ind->random_sounds); } /* We need to remove the tiles layouts */ diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h index fd0dd699d..51667c216 100644 --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -140,8 +140,8 @@ struct NewGRFSpriteLayout : ZeroedMemoryAllocator, DrawTileSprites { virtual ~NewGRFSpriteLayout() { - free(const_cast<DrawTileSeqStruct*>(this->seq)); - free(const_cast<TileLayoutRegisters*>(this->registers)); + free(this->seq); + free(this->registers); } /** diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index 1ebf5bcf7..03ac7ce7f 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -20,8 +20,8 @@ INSTANTIATE_POOL_METHODS(SpriteGroup) RealSpriteGroup::~RealSpriteGroup() { - free((void*)this->loaded); - free((void*)this->loading); + free(this->loaded); + free(this->loading); } DeterministicSpriteGroup::~DeterministicSpriteGroup() @@ -32,7 +32,7 @@ DeterministicSpriteGroup::~DeterministicSpriteGroup() RandomizedSpriteGroup::~RandomizedSpriteGroup() { - free((void*)this->groups); + free(this->groups); } TemporaryStorageArray<int32, 0x110> _temp_store; diff --git a/src/openttd.cpp b/src/openttd.cpp index 83545cb89..4a248e7fc 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -806,9 +806,9 @@ int ttd_main(int argc, char *argv[]) /* Reset windowing system, stop drivers, free used memory, ... */ ShutdownGame(); - free(const_cast<char *>(BaseGraphics::ini_set)); - free(const_cast<char *>(BaseSounds::ini_set)); - free(const_cast<char *>(BaseMusic::ini_set)); + free(BaseGraphics::ini_set); + free(BaseSounds::ini_set); + free(BaseMusic::ini_set); free(_ini_musicdriver); free(_ini_sounddriver); free(_ini_videodriver); diff --git a/src/querystring_gui.h b/src/querystring_gui.h index 52da49d77..c1ae14606 100644 --- a/src/querystring_gui.h +++ b/src/querystring_gui.h @@ -48,7 +48,7 @@ struct QueryString { */ ~QueryString() { - free((void*)this->orig); + free(this->orig); } private: diff --git a/src/script/script_info.cpp b/src/script/script_info.cpp index dc21e26f2..a01456130 100644 --- a/src/script/script_info.cpp +++ b/src/script/script_info.cpp @@ -23,13 +23,13 @@ static const int MAX_CREATEINSTANCE_OPS = 100000; ScriptFileInfo::~ScriptFileInfo() { - free((void *)this->author); - free((void *)this->name); - free((void *)this->short_name); - free((void *)this->description); - free((void *)this->date); - free((void *)this->instance_name); - free((void *)this->url); + free(this->author); + free(this->name); + free(this->short_name); + free(this->description); + free(this->date); + free(this->instance_name); + free(this->url); free(this->main_script); free(this->tar_file); free(this->SQ_instance); diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 7237574aa..9df318e13 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -448,7 +448,7 @@ struct GameOptionsWindow : Window { if (_game_mode == GM_MENU) { const char *name = T::GetSet(index)->name; - free(const_cast<char *>(T::ini_set)); + free(T::ini_set); T::ini_set = strdup(name); T::SetSet(name); diff --git a/src/stdafx.h b/src/stdafx.h index bee855169..7120ec175 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -438,6 +438,15 @@ void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2); #endif /** + * Version of the standard free that accepts const pointers. + * @param ptr The data to free. + */ +static FORCEINLINE void free(const void *ptr) +{ + free(const_cast<void *>(ptr)); +} + +/** * The largest value that can be entered in a variable * @param type the type of the variable */ diff --git a/src/tar_type.h b/src/tar_type.h index 272ae5da4..dae1df05c 100644 --- a/src/tar_type.h +++ b/src/tar_type.h @@ -24,7 +24,7 @@ struct TarListEntry { * to free filename, which isn't set at that moment... but because it * initializes the variable with garbage, it's going to segfault. */ TarListEntry() : filename(NULL), dirname(NULL) {} - ~TarListEntry() { free((void*)this->filename); free((void*)this->dirname); } + ~TarListEntry() { free(this->filename); free(this->dirname); } }; struct TarFileListEntry { |