From 7803378d820da963ca219f77a0ada61b34786939 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Wed, 31 Aug 2022 18:52:01 +0300 Subject: [PATCH] Fix some warnings --- src/character_editor.cc | 22 +++++++++++----------- src/endgame.cc | 22 +++++++++++----------- src/game_dialog.cc | 5 ++--- src/game_sound.cc | 4 ++-- src/loadsave.cc | 2 +- src/proto.cc | 12 ++++++------ 6 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/character_editor.cc b/src/character_editor.cc index fc14d74..9827b92 100644 --- a/src/character_editor.cc +++ b/src/character_editor.cc @@ -1926,7 +1926,7 @@ static int _get_input_str(int win, int cancelKeyCode, char* text, int maxLength, char copy[257]; strcpy(copy, text); - int nameLength = strlen(text); + size_t nameLength = strlen(text); copy[nameLength] = ' '; copy[nameLength + 1] = '\0'; @@ -2012,8 +2012,8 @@ bool _isdoschar(int ch) return true; } - int length = strlen(punctuations); - for (int index = 0; index < length; index++) { + size_t length = strlen(punctuations); + for (size_t index = 0; index < length; index++) { if (punctuations[index] == ch) { return true; } @@ -4272,7 +4272,7 @@ static int characterPrintToFile(const char* fileName) // NOTE: Uninline. padding[0] = '\0'; - _AddSpaces(padding, (80 - strlen(title1)) / 2 - 2); + _AddSpaces(padding, (80 - static_cast(strlen(title1))) / 2 - 2); strcat(padding, title1); strcat(padding, "\n"); @@ -4283,7 +4283,7 @@ static int characterPrintToFile(const char* fileName) // NOTE: Uninline. padding[0] = '\0'; - _AddSpaces(padding, (80 - strlen(title1)) / 2 - 2); + _AddSpaces(padding, (80 - static_cast(strlen(title1))) / 2 - 2); strcat(padding, title1); strcat(padding, "\n"); @@ -4303,7 +4303,7 @@ static int characterPrintToFile(const char* fileName) // NOTE: Uninline. padding[0] = '\0'; - _AddSpaces(padding, (80 - strlen(title1)) / 2 - 2); + _AddSpaces(padding, (80 - static_cast(strlen(title1))) / 2 - 2); strcat(padding, title1); strcat(padding, "\n"); @@ -4318,7 +4318,7 @@ static int characterPrintToFile(const char* fileName) getmsg(&gCharacterEditorMessageList, &gCharacterEditorMessageListItem, 642), critterGetName(gDude)); - int paddingLength = 27 - strlen(title1); + int paddingLength = 27 - static_cast(strlen(title1)); if (paddingLength > 0) { // NOTE: Uninline. padding[0] = '\0'; @@ -4351,7 +4351,7 @@ static int characterPrintToFile(const char* fileName) getmsg(&gCharacterEditorMessageList, &gCharacterEditorMessageListItem, 648), _itostndn(pcGetStat(PC_STAT_EXPERIENCE), title3)); - paddingLength = 12 - strlen(title3); + paddingLength = 12 - static_cast(strlen(title3)); if (paddingLength > 0) { // NOTE: Uninline. padding[0] = '\0'; @@ -4616,7 +4616,7 @@ static int characterPrintToFile(const char* fileName) sprintf(title1, "%s ", skillGetName(skill)); // NOTE: Uninline. - _AddDots(title1 + strlen(title1), 16 - strlen(title1)); + _AddDots(title1 + strlen(title1), 16 - static_cast(strlen(title1))); bool hasKillType = false; @@ -4626,7 +4626,7 @@ static int characterPrintToFile(const char* fileName) sprintf(title2, "%s ", killTypeGetName(killType)); // NOTE: Uninline. - _AddDots(title2 + strlen(title2), 16 - strlen(title2)); + _AddDots(title2 + strlen(title2), 16 - static_cast(strlen(title2))); sprintf(title3, " %s %.3d%% %s %.3d\n", @@ -4671,7 +4671,7 @@ static int characterPrintToFile(const char* fileName) _itostndn(inventoryItem->quantity, title3), objectGetName(inventoryItem->item)); - int length = 25 - strlen(title2); + int length = 25 - static_cast(strlen(title2)); if (length < 0) { length = 0; } diff --git a/src/endgame.cc b/src/endgame.cc index d49a2fe..6795538 100644 --- a/src/endgame.cc +++ b/src/endgame.cc @@ -661,7 +661,7 @@ static void endgameEndingVoiceOverInit(const char* fileBaseName) unsigned int timing = 0; for (int index = 0; index < gEndgameEndingSubtitlesLength; index++) { - double charactersCount = strlen(gEndgameEndingSubtitles[index]); + double charactersCount = static_cast(strlen(gEndgameEndingSubtitles[index])); // NOTE: There is floating point math at 0x4402E6 used to add // timing. timing += (unsigned int)trunc(charactersCount * durationPerCharacter * 1000.0); @@ -758,7 +758,7 @@ static int endgameEndingSubtitlesLoad(const char* filePath) if (gEndgameEndingSubtitlesLength < ENDGAME_ENDING_MAX_SUBTITLES) { gEndgameEndingSubtitles[gEndgameEndingSubtitlesLength] = internal_strdup(pch + 1); gEndgameEndingSubtitlesLength++; - gEndgameEndingSubtitlesCharactersCount += strlen(pch + 1); + gEndgameEndingSubtitlesCharactersCount += static_cast(strlen(pch + 1)); } } } @@ -861,7 +861,7 @@ static int endgameEndingInit() const char* delim = " \t,"; EndgameEnding entry; EndgameEnding* entries; - int narrator_file_len; + size_t narratorFileNameLength; if (gEndgameEndings != NULL) { internal_free(gEndgameEndings); @@ -913,9 +913,9 @@ static int endgameEndingInit() strcpy(entry.voiceOverBaseName, tok); - narrator_file_len = strlen(entry.voiceOverBaseName); - if (isspace(entry.voiceOverBaseName[narrator_file_len - 1])) { - entry.voiceOverBaseName[narrator_file_len - 1] = '\0'; + narratorFileNameLength = strlen(entry.voiceOverBaseName); + if (isspace(entry.voiceOverBaseName[narratorFileNameLength - 1])) { + entry.voiceOverBaseName[narratorFileNameLength - 1] = '\0'; } tok = strtok(NULL, delim); @@ -971,7 +971,7 @@ int endgameDeathEndingInit() char* tok; EndgameDeathEnding entry; EndgameDeathEnding* entries; - int narrator_file_len; + size_t narratorFileNameLength; strcpy(gEndgameDeathEndingFileName, "narrator\\nar_5"); @@ -1038,13 +1038,13 @@ int endgameDeathEndingInit() } // this code is slightly different from the original, but does the same thing - narrator_file_len = strlen(tok); - strncpy(entry.voiceOverBaseName, tok, narrator_file_len); + narratorFileNameLength = strlen(tok); + strncpy(entry.voiceOverBaseName, tok, narratorFileNameLength); entry.enabled = false; - if (isspace(entry.voiceOverBaseName[narrator_file_len - 1])) { - entry.voiceOverBaseName[narrator_file_len - 1] = '\0'; + if (isspace(entry.voiceOverBaseName[narratorFileNameLength - 1])) { + entry.voiceOverBaseName[narratorFileNameLength - 1] = '\0'; } entries = (EndgameDeathEnding*)internal_realloc(gEndgameDeathEndings, sizeof(*entries) * (gEndgameDeathEndingsLength + 1)); diff --git a/src/game_dialog.cc b/src/game_dialog.cc index 41b0cde..ede0587 100644 --- a/src/game_dialog.cc +++ b/src/game_dialog.cc @@ -1709,7 +1709,6 @@ int _gdProcessInit() int downBtn; int optionsWindowX; int optionsWindowY; - int fid; int replyWindowX = (screenGetWidth() - GAME_DIALOG_WINDOW_WIDTH) / 2 + GAME_DIALOG_REPLY_WINDOW_X; int replyWindowY = (screenGetHeight() - GAME_DIALOG_WINDOW_HEIGHT) / 2 + GAME_DIALOG_REPLY_WINDOW_Y; @@ -3024,7 +3023,7 @@ int gameDialogDrawText(unsigned char* buffer, Rect* rect, char* string, int* a4, } if (a4 != NULL) { - *a4 += strlen(start) + 1; + *a4 += static_cast(strlen(start)) + 1; } rect->top += height; @@ -3055,7 +3054,7 @@ int gameDialogDrawText(unsigned char* buffer, Rect* rect, char* string, int* a4, } if (a4 != NULL && end != NULL) { - *a4 += strlen(start) + 1; + *a4 += static_cast(strlen(start)) + 1; } rect->top += height; diff --git a/src/game_sound.cc b/src/game_sound.cc index 84ef973..4940ab4 100644 --- a/src/game_sound.cc +++ b/src/game_sound.cc @@ -1817,7 +1817,7 @@ int gameSoundFindBackgroundSoundPathWithCopy(char* dest, const char* src) int gameSoundFindBackgroundSoundPath(char* dest, const char* src) { char path[COMPAT_MAX_PATH]; - int len; + size_t len; len = strlen(src) + strlen(".ACM"); if (strlen(_sound_music_path1) + len > COMPAT_MAX_PATH || strlen(_sound_music_path2) + len > COMPAT_MAX_PATH) { @@ -1962,7 +1962,7 @@ int speechPlay() // 0x452208 int _gsound_get_music_path(char** out_value, const char* key) { - int v3; + size_t v3; char* v4; char* value; diff --git a/src/loadsave.cc b/src/loadsave.cc index 28f68e8..05900ab 100644 --- a/src/loadsave.cc +++ b/src/loadsave.cc @@ -2115,7 +2115,7 @@ static int _get_input_str2(int win, int doneKeyCode, int cancelKeyCode, char* de char text[256]; strcpy(text, description); - int textLength = strlen(text); + size_t textLength = strlen(text); text[textLength] = ' '; text[textLength + 1] = '\0'; diff --git a/src/proto.cc b/src/proto.cc index 0445b26..eb12a09 100644 --- a/src/proto.cc +++ b/src/proto.cc @@ -437,12 +437,13 @@ static int objectCritterCombatDataWrite(CritterCombatData* data, File* stream) int objectDataRead(Object* obj, File* stream) { Proto* proto; + int temp; Inventory* inventory = &(obj->data.inventory); if (fileReadInt32(stream, &(inventory->length)) == -1) return -1; if (fileReadInt32(stream, &(inventory->capacity)) == -1) return -1; - // TODO: See below. - if (fileReadInt32(stream, (int*)&(inventory->items)) == -1) return -1; + // CE: Original code reads inventory items pointer which is meaningless. + if (fileReadInt32(stream, &temp) == -1) return -1; if (PID_TYPE(obj->pid) == OBJ_TYPE_CRITTER) { if (fileReadInt32(stream, &(obj->data.critter.field_0)) == -1) return -1; @@ -537,9 +538,8 @@ int objectDataWrite(Object* obj, File* stream) ObjectData* data = &(obj->data); if (fileWriteInt32(stream, data->inventory.length) == -1) return -1; if (fileWriteInt32(stream, data->inventory.capacity) == -1) return -1; - // TODO: Why do we need to write address of pointer? That probably means - // this field is shared with something else. - if (fileWriteInt32(stream, (intptr_t)data->inventory.items) == -1) return -1; + // CE: Original code writes inventory items pointer, which is meaningless. + if (fileWriteInt32(stream, 0) == -1) return -1; if (PID_TYPE(obj->pid) == OBJ_TYPE_CRITTER) { if (fileWriteInt32(stream, data->flags) == -1) return -1; @@ -1059,7 +1059,7 @@ int protoGetDataMember(int pid, int member, ProtoDataMemberValue* value) int protoInit() { char* master_patches; - int len; + size_t len; MessageListItem messageListItem; char path[COMPAT_MAX_PATH]; int i;