Fix some warnings

This commit is contained in:
Alexander Batalov 2022-08-31 18:52:01 +03:00
parent 893a116fb4
commit 7803378d82
6 changed files with 33 additions and 34 deletions

View File

@ -1926,7 +1926,7 @@ static int _get_input_str(int win, int cancelKeyCode, char* text, int maxLength,
char copy[257]; char copy[257];
strcpy(copy, text); strcpy(copy, text);
int nameLength = strlen(text); size_t nameLength = strlen(text);
copy[nameLength] = ' '; copy[nameLength] = ' ';
copy[nameLength + 1] = '\0'; copy[nameLength + 1] = '\0';
@ -2012,8 +2012,8 @@ bool _isdoschar(int ch)
return true; return true;
} }
int length = strlen(punctuations); size_t length = strlen(punctuations);
for (int index = 0; index < length; index++) { for (size_t index = 0; index < length; index++) {
if (punctuations[index] == ch) { if (punctuations[index] == ch) {
return true; return true;
} }
@ -4272,7 +4272,7 @@ static int characterPrintToFile(const char* fileName)
// NOTE: Uninline. // NOTE: Uninline.
padding[0] = '\0'; padding[0] = '\0';
_AddSpaces(padding, (80 - strlen(title1)) / 2 - 2); _AddSpaces(padding, (80 - static_cast<int>(strlen(title1))) / 2 - 2);
strcat(padding, title1); strcat(padding, title1);
strcat(padding, "\n"); strcat(padding, "\n");
@ -4283,7 +4283,7 @@ static int characterPrintToFile(const char* fileName)
// NOTE: Uninline. // NOTE: Uninline.
padding[0] = '\0'; padding[0] = '\0';
_AddSpaces(padding, (80 - strlen(title1)) / 2 - 2); _AddSpaces(padding, (80 - static_cast<int>(strlen(title1))) / 2 - 2);
strcat(padding, title1); strcat(padding, title1);
strcat(padding, "\n"); strcat(padding, "\n");
@ -4303,7 +4303,7 @@ static int characterPrintToFile(const char* fileName)
// NOTE: Uninline. // NOTE: Uninline.
padding[0] = '\0'; padding[0] = '\0';
_AddSpaces(padding, (80 - strlen(title1)) / 2 - 2); _AddSpaces(padding, (80 - static_cast<int>(strlen(title1))) / 2 - 2);
strcat(padding, title1); strcat(padding, title1);
strcat(padding, "\n"); strcat(padding, "\n");
@ -4318,7 +4318,7 @@ static int characterPrintToFile(const char* fileName)
getmsg(&gCharacterEditorMessageList, &gCharacterEditorMessageListItem, 642), getmsg(&gCharacterEditorMessageList, &gCharacterEditorMessageListItem, 642),
critterGetName(gDude)); critterGetName(gDude));
int paddingLength = 27 - strlen(title1); int paddingLength = 27 - static_cast<int>(strlen(title1));
if (paddingLength > 0) { if (paddingLength > 0) {
// NOTE: Uninline. // NOTE: Uninline.
padding[0] = '\0'; padding[0] = '\0';
@ -4351,7 +4351,7 @@ static int characterPrintToFile(const char* fileName)
getmsg(&gCharacterEditorMessageList, &gCharacterEditorMessageListItem, 648), getmsg(&gCharacterEditorMessageList, &gCharacterEditorMessageListItem, 648),
_itostndn(pcGetStat(PC_STAT_EXPERIENCE), title3)); _itostndn(pcGetStat(PC_STAT_EXPERIENCE), title3));
paddingLength = 12 - strlen(title3); paddingLength = 12 - static_cast<int>(strlen(title3));
if (paddingLength > 0) { if (paddingLength > 0) {
// NOTE: Uninline. // NOTE: Uninline.
padding[0] = '\0'; padding[0] = '\0';
@ -4616,7 +4616,7 @@ static int characterPrintToFile(const char* fileName)
sprintf(title1, "%s ", skillGetName(skill)); sprintf(title1, "%s ", skillGetName(skill));
// NOTE: Uninline. // NOTE: Uninline.
_AddDots(title1 + strlen(title1), 16 - strlen(title1)); _AddDots(title1 + strlen(title1), 16 - static_cast<int>(strlen(title1)));
bool hasKillType = false; bool hasKillType = false;
@ -4626,7 +4626,7 @@ static int characterPrintToFile(const char* fileName)
sprintf(title2, "%s ", killTypeGetName(killType)); sprintf(title2, "%s ", killTypeGetName(killType));
// NOTE: Uninline. // NOTE: Uninline.
_AddDots(title2 + strlen(title2), 16 - strlen(title2)); _AddDots(title2 + strlen(title2), 16 - static_cast<int>(strlen(title2)));
sprintf(title3, sprintf(title3,
" %s %.3d%% %s %.3d\n", " %s %.3d%% %s %.3d\n",
@ -4671,7 +4671,7 @@ static int characterPrintToFile(const char* fileName)
_itostndn(inventoryItem->quantity, title3), _itostndn(inventoryItem->quantity, title3),
objectGetName(inventoryItem->item)); objectGetName(inventoryItem->item));
int length = 25 - strlen(title2); int length = 25 - static_cast<int>(strlen(title2));
if (length < 0) { if (length < 0) {
length = 0; length = 0;
} }

View File

@ -661,7 +661,7 @@ static void endgameEndingVoiceOverInit(const char* fileBaseName)
unsigned int timing = 0; unsigned int timing = 0;
for (int index = 0; index < gEndgameEndingSubtitlesLength; index++) { for (int index = 0; index < gEndgameEndingSubtitlesLength; index++) {
double charactersCount = strlen(gEndgameEndingSubtitles[index]); double charactersCount = static_cast<double>(strlen(gEndgameEndingSubtitles[index]));
// NOTE: There is floating point math at 0x4402E6 used to add // NOTE: There is floating point math at 0x4402E6 used to add
// timing. // timing.
timing += (unsigned int)trunc(charactersCount * durationPerCharacter * 1000.0); timing += (unsigned int)trunc(charactersCount * durationPerCharacter * 1000.0);
@ -758,7 +758,7 @@ static int endgameEndingSubtitlesLoad(const char* filePath)
if (gEndgameEndingSubtitlesLength < ENDGAME_ENDING_MAX_SUBTITLES) { if (gEndgameEndingSubtitlesLength < ENDGAME_ENDING_MAX_SUBTITLES) {
gEndgameEndingSubtitles[gEndgameEndingSubtitlesLength] = internal_strdup(pch + 1); gEndgameEndingSubtitles[gEndgameEndingSubtitlesLength] = internal_strdup(pch + 1);
gEndgameEndingSubtitlesLength++; gEndgameEndingSubtitlesLength++;
gEndgameEndingSubtitlesCharactersCount += strlen(pch + 1); gEndgameEndingSubtitlesCharactersCount += static_cast<int>(strlen(pch + 1));
} }
} }
} }
@ -861,7 +861,7 @@ static int endgameEndingInit()
const char* delim = " \t,"; const char* delim = " \t,";
EndgameEnding entry; EndgameEnding entry;
EndgameEnding* entries; EndgameEnding* entries;
int narrator_file_len; size_t narratorFileNameLength;
if (gEndgameEndings != NULL) { if (gEndgameEndings != NULL) {
internal_free(gEndgameEndings); internal_free(gEndgameEndings);
@ -913,9 +913,9 @@ static int endgameEndingInit()
strcpy(entry.voiceOverBaseName, tok); strcpy(entry.voiceOverBaseName, tok);
narrator_file_len = strlen(entry.voiceOverBaseName); narratorFileNameLength = strlen(entry.voiceOverBaseName);
if (isspace(entry.voiceOverBaseName[narrator_file_len - 1])) { if (isspace(entry.voiceOverBaseName[narratorFileNameLength - 1])) {
entry.voiceOverBaseName[narrator_file_len - 1] = '\0'; entry.voiceOverBaseName[narratorFileNameLength - 1] = '\0';
} }
tok = strtok(NULL, delim); tok = strtok(NULL, delim);
@ -971,7 +971,7 @@ int endgameDeathEndingInit()
char* tok; char* tok;
EndgameDeathEnding entry; EndgameDeathEnding entry;
EndgameDeathEnding* entries; EndgameDeathEnding* entries;
int narrator_file_len; size_t narratorFileNameLength;
strcpy(gEndgameDeathEndingFileName, "narrator\\nar_5"); strcpy(gEndgameDeathEndingFileName, "narrator\\nar_5");
@ -1038,13 +1038,13 @@ int endgameDeathEndingInit()
} }
// this code is slightly different from the original, but does the same thing // this code is slightly different from the original, but does the same thing
narrator_file_len = strlen(tok); narratorFileNameLength = strlen(tok);
strncpy(entry.voiceOverBaseName, tok, narrator_file_len); strncpy(entry.voiceOverBaseName, tok, narratorFileNameLength);
entry.enabled = false; entry.enabled = false;
if (isspace(entry.voiceOverBaseName[narrator_file_len - 1])) { if (isspace(entry.voiceOverBaseName[narratorFileNameLength - 1])) {
entry.voiceOverBaseName[narrator_file_len - 1] = '\0'; entry.voiceOverBaseName[narratorFileNameLength - 1] = '\0';
} }
entries = (EndgameDeathEnding*)internal_realloc(gEndgameDeathEndings, sizeof(*entries) * (gEndgameDeathEndingsLength + 1)); entries = (EndgameDeathEnding*)internal_realloc(gEndgameDeathEndings, sizeof(*entries) * (gEndgameDeathEndingsLength + 1));

View File

@ -1709,7 +1709,6 @@ int _gdProcessInit()
int downBtn; int downBtn;
int optionsWindowX; int optionsWindowX;
int optionsWindowY; int optionsWindowY;
int fid;
int replyWindowX = (screenGetWidth() - GAME_DIALOG_WINDOW_WIDTH) / 2 + GAME_DIALOG_REPLY_WINDOW_X; 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; 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) { if (a4 != NULL) {
*a4 += strlen(start) + 1; *a4 += static_cast<int>(strlen(start)) + 1;
} }
rect->top += height; rect->top += height;
@ -3055,7 +3054,7 @@ int gameDialogDrawText(unsigned char* buffer, Rect* rect, char* string, int* a4,
} }
if (a4 != NULL && end != NULL) { if (a4 != NULL && end != NULL) {
*a4 += strlen(start) + 1; *a4 += static_cast<int>(strlen(start)) + 1;
} }
rect->top += height; rect->top += height;

View File

@ -1817,7 +1817,7 @@ int gameSoundFindBackgroundSoundPathWithCopy(char* dest, const char* src)
int gameSoundFindBackgroundSoundPath(char* dest, const char* src) int gameSoundFindBackgroundSoundPath(char* dest, const char* src)
{ {
char path[COMPAT_MAX_PATH]; char path[COMPAT_MAX_PATH];
int len; size_t len;
len = strlen(src) + strlen(".ACM"); len = strlen(src) + strlen(".ACM");
if (strlen(_sound_music_path1) + len > COMPAT_MAX_PATH || strlen(_sound_music_path2) + len > COMPAT_MAX_PATH) { if (strlen(_sound_music_path1) + len > COMPAT_MAX_PATH || strlen(_sound_music_path2) + len > COMPAT_MAX_PATH) {
@ -1962,7 +1962,7 @@ int speechPlay()
// 0x452208 // 0x452208
int _gsound_get_music_path(char** out_value, const char* key) int _gsound_get_music_path(char** out_value, const char* key)
{ {
int v3; size_t v3;
char* v4; char* v4;
char* value; char* value;

View File

@ -2115,7 +2115,7 @@ static int _get_input_str2(int win, int doneKeyCode, int cancelKeyCode, char* de
char text[256]; char text[256];
strcpy(text, description); strcpy(text, description);
int textLength = strlen(text); size_t textLength = strlen(text);
text[textLength] = ' '; text[textLength] = ' ';
text[textLength + 1] = '\0'; text[textLength + 1] = '\0';

View File

@ -437,12 +437,13 @@ static int objectCritterCombatDataWrite(CritterCombatData* data, File* stream)
int objectDataRead(Object* obj, File* stream) int objectDataRead(Object* obj, File* stream)
{ {
Proto* proto; Proto* proto;
int temp;
Inventory* inventory = &(obj->data.inventory); Inventory* inventory = &(obj->data.inventory);
if (fileReadInt32(stream, &(inventory->length)) == -1) return -1; if (fileReadInt32(stream, &(inventory->length)) == -1) return -1;
if (fileReadInt32(stream, &(inventory->capacity)) == -1) return -1; if (fileReadInt32(stream, &(inventory->capacity)) == -1) return -1;
// TODO: See below. // CE: Original code reads inventory items pointer which is meaningless.
if (fileReadInt32(stream, (int*)&(inventory->items)) == -1) return -1; if (fileReadInt32(stream, &temp) == -1) return -1;
if (PID_TYPE(obj->pid) == OBJ_TYPE_CRITTER) { if (PID_TYPE(obj->pid) == OBJ_TYPE_CRITTER) {
if (fileReadInt32(stream, &(obj->data.critter.field_0)) == -1) return -1; 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); ObjectData* data = &(obj->data);
if (fileWriteInt32(stream, data->inventory.length) == -1) return -1; if (fileWriteInt32(stream, data->inventory.length) == -1) return -1;
if (fileWriteInt32(stream, data->inventory.capacity) == -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 // CE: Original code writes inventory items pointer, which is meaningless.
// this field is shared with something else. if (fileWriteInt32(stream, 0) == -1) return -1;
if (fileWriteInt32(stream, (intptr_t)data->inventory.items) == -1) return -1;
if (PID_TYPE(obj->pid) == OBJ_TYPE_CRITTER) { if (PID_TYPE(obj->pid) == OBJ_TYPE_CRITTER) {
if (fileWriteInt32(stream, data->flags) == -1) return -1; if (fileWriteInt32(stream, data->flags) == -1) return -1;
@ -1059,7 +1059,7 @@ int protoGetDataMember(int pid, int member, ProtoDataMemberValue* value)
int protoInit() int protoInit()
{ {
char* master_patches; char* master_patches;
int len; size_t len;
MessageListItem messageListItem; MessageListItem messageListItem;
char path[COMPAT_MAX_PATH]; char path[COMPAT_MAX_PATH];
int i; int i;