1
0
Fork 0

Codefix: Avoid type-casting function pointer with incorrect type. (#12929)

Make `AutolengthProc` take `int` instead of `void *`, avoiding pointer parameters.
pull/12836/head
Peter Nelson 2024-09-12 06:49:45 +01:00 committed by GitHub
parent 9631c68ce6
commit 7f5a3eaf83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 8 deletions

View File

@ -41,9 +41,9 @@ static const SaveLoad _ai_running_desc[] = {
SLEG_CONDVAR("running_version", _ai_saveload_version, SLE_UINT32, SLV_AI_LOCAL_CONFIG, SL_MAX_VERSION),
};
static void SaveReal_AIPL(int *index_ptr)
static void SaveReal_AIPL(int arg)
{
CompanyID index = (CompanyID)*index_ptr;
CompanyID index = static_cast<CompanyID>(arg);
AIConfig *config = AIConfig::GetConfig(index, AIConfig::SSS_FORCE_GAME);
if (config->HasScript()) {
@ -162,7 +162,7 @@ struct AIPLChunkHandler : ChunkHandler {
for (int i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
SlSetArrayIndex(i);
SlAutolength((AutolengthProc *)SaveReal_AIPL, &i);
SlAutolength(SaveReal_AIPL, i);
}
}
};

View File

@ -32,7 +32,7 @@ static const SaveLoad _game_script_desc[] = {
SLEG_VAR("version", _game_saveload_version, SLE_UINT32),
};
static void SaveReal_GSDT(int *)
static void SaveReal_GSDT(int)
{
GameConfig *config = GameConfig::GetConfig();
@ -109,7 +109,7 @@ struct GSDTChunkHandler : ChunkHandler {
{
SlTableHeader(_game_script_desc);
SlSetArrayIndex(0);
SlAutolength((AutolengthProc *)SaveReal_GSDT, nullptr);
SlAutolength(SaveReal_GSDT, 0);
}
};

View File

@ -1925,7 +1925,7 @@ void SlGlobList(const SaveLoadTable &slt)
* @param proc The callback procedure that is called
* @param arg The variable that will be used for the callback procedure
*/
void SlAutolength(AutolengthProc *proc, void *arg)
void SlAutolength(AutolengthProc *proc, int arg)
{
assert(_sl.action == SLA_SAVE);

View File

@ -436,7 +436,7 @@ void DoAutoOrNetsave(FiosNumberedSaveName &counter);
SaveOrLoadResult SaveWithFilter(std::shared_ptr<struct SaveFilter> writer, bool threaded);
SaveOrLoadResult LoadWithFilter(std::shared_ptr<struct LoadFilter> reader);
typedef void AutolengthProc(void *arg);
typedef void AutolengthProc(int);
/** Type of a chunk. */
enum ChunkType {
@ -1290,7 +1290,7 @@ int SlIterateArray();
void SlSetStructListLength(size_t length);
size_t SlGetStructListLength(size_t limit);
void SlAutolength(AutolengthProc *proc, void *arg);
void SlAutolength(AutolengthProc *proc, int arg);
size_t SlGetFieldLength();
void SlSetLength(size_t length);
size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld);