From 1d5c73679fd334d71060e002fa057460848f67c2 Mon Sep 17 00:00:00 2001 From: Eric Branlund Date: Sat, 4 Apr 2020 12:13:07 -0700 Subject: [PATCH] Avoided compiler warnings about a 32-bit integer being passed to a %ld or %lu format specifier by adding casts, changing the specifier, or changing the type of a local variable. --- src/bldg.c | 44 ++++++++++++++++++++++---------------------- src/cmd3.c | 10 ++++------ src/cmd4.c | 2 +- src/files.c | 6 +++--- src/spells2.c | 4 ++-- src/wizard1.c | 4 ++-- src/wizard2.c | 2 +- 7 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/bldg.c b/src/bldg.c index ef40e4fc9..99effc226 100644 --- a/src/bldg.c +++ b/src/bldg.c @@ -132,9 +132,9 @@ static void show_building(building_type* bldg) { action_color = TERM_YELLOW; #ifdef JP -sprintf(buff, "($%ld)", bldg->member_costs[i]); + sprintf(buff, "($%ld)", (long int)bldg->member_costs[i]); #else - sprintf(buff, "(%ldgp)", bldg->member_costs[i]); + sprintf(buff, "(%ldgp)", (long int)bldg->member_costs[i]); #endif } @@ -142,9 +142,9 @@ sprintf(buff, "($%ld)", bldg->member_costs[i]); { action_color = TERM_YELLOW; #ifdef JP -sprintf(buff, "($%ld)", bldg->other_costs[i]); + sprintf(buff, "($%ld)", (long int)bldg->other_costs[i]); #else - sprintf(buff, "(%ldgp)", bldg->other_costs[i]); + sprintf(buff, "(%ldgp)", (long int)bldg->other_costs[i]); #endif } @@ -171,9 +171,9 @@ strcpy(buff, "( { action_color = TERM_YELLOW; #ifdef JP -sprintf(buff, "($%ld)", bldg->member_costs[i]); + sprintf(buff, "($%ld)", (long int)bldg->member_costs[i]); #else - sprintf(buff, "(%ldgp)", bldg->member_costs[i]); + sprintf(buff, "(%ldgp)", (long int)bldg->member_costs[i]); #endif } @@ -181,9 +181,9 @@ sprintf(buff, "($%ld)", bldg->member_costs[i]); { action_color = TERM_YELLOW; #ifdef JP -sprintf(buff, "($%ld)", bldg->other_costs[i]); + sprintf(buff, "($%ld)", (long int)bldg->other_costs[i]); #else - sprintf(buff, "(%ldgp)", bldg->other_costs[i]); + sprintf(buff, "(%ldgp)", (long int)bldg->other_costs[i]); #endif } @@ -204,9 +204,9 @@ strcpy(buff, "( { action_color = TERM_YELLOW; #ifdef JP -sprintf(buff, "($%ld)", bldg->member_costs[i]); + sprintf(buff, "($%ld)", (long int)bldg->member_costs[i]); #else - sprintf(buff, "(%ldgp)", bldg->member_costs[i]); + sprintf(buff, "(%ldgp)", (long int)bldg->member_costs[i]); #endif } @@ -1267,9 +1267,9 @@ static bool gamble_comm(int cmd) /* Get the wager */ strcpy(out_val, ""); #ifdef JP -sprintf(tmp_str,"ÅÒ¤±¶â (1-%ld)¡©", maxbet); + sprintf(tmp_str,"ÅÒ¤±¶â (1-%ld)¡©", (long int)maxbet); #else - sprintf(tmp_str,"Your wager (1-%ld) ? ", maxbet); + sprintf(tmp_str,"Your wager (1-%ld) ? ", (long int)maxbet); #endif @@ -1324,17 +1324,17 @@ msg_print(" oldgold = p_ptr->au; #ifdef JP -sprintf(tmp_str, "¥²¡¼¥àÁ°¤Î½ê»ý¶â: %9ld", oldgold); + sprintf(tmp_str, "¥²¡¼¥àÁ°¤Î½ê»ý¶â: %9ld", (long int)oldgold); #else - sprintf(tmp_str, "Gold before game: %9ld", oldgold); + sprintf(tmp_str, "Gold before game: %9ld", (long int)oldgold); #endif prt(tmp_str, 20, 2); #ifdef JP -sprintf(tmp_str, "¸½ºß¤Î³Ý¤±¶â: %9ld", wager); + sprintf(tmp_str, "¸½ºß¤Î³Ý¤±¶â: %9ld", (long int)wager); #else - sprintf(tmp_str, "Current Wager: %9ld", wager); + sprintf(tmp_str, "Current Wager: %9ld", (long int)wager); #endif prt(tmp_str, 21, 2); @@ -1603,9 +1603,9 @@ prt(" prt("", 17, 37); } #ifdef JP -sprintf(tmp_str, "¸½ºß¤Î½ê»ý¶â: %9ld", p_ptr->au); + sprintf(tmp_str, "¸½ºß¤Î½ê»ý¶â: %9ld", (long int)p_ptr->au); #else - sprintf(tmp_str, "Current Gold: %9ld", p_ptr->au); + sprintf(tmp_str, "Current Gold: %9ld", (long int)p_ptr->au); #endif prt(tmp_str, 22, 2); @@ -1957,9 +1957,9 @@ static bool kakutoujou(void) monster_race *r_ptr = &r_info[battle_mon[i]]; #ifdef JP - sprintf(buf,"%d) %-58s %4ld.%02ldÇÜ", i+1, format("%s%s",r_name + r_ptr->name, (r_ptr->flags1 & RF1_UNIQUE) ? "¤â¤É¤­" : " "), mon_odds[i]/100, mon_odds[i]%100); + sprintf(buf,"%d) %-58s %4ld.%02ldÇÜ", i+1, format("%s%s",r_name + r_ptr->name, (r_ptr->flags1 & RF1_UNIQUE) ? "¤â¤É¤­" : " "), (long int)mon_odds[i]/100, (long int)mon_odds[i]%100); #else - sprintf(buf,"%d) %-58s %4ld.%02ld", i+1, format("%s%s", (r_ptr->flags1 & RF1_UNIQUE) ? "Fake " : "", r_name + r_ptr->name), mon_odds[i]/100, mon_odds[i]%100); + sprintf(buf,"%d) %-58s %4ld.%02ld", i+1, format("%s%s", (r_ptr->flags1 & RF1_UNIQUE) ? "Fake " : "", r_name + r_ptr->name), (long int)mon_odds[i]/100, (long int)mon_odds[i]%100); #endif prt(buf, 5+i, 1); } @@ -1999,9 +1999,9 @@ static bool kakutoujou(void) /* Get the wager */ strcpy(out_val, ""); #ifdef JP -sprintf(tmp_str,"ÅÒ¤±¶â (1-%ld)¡©", maxbet); + sprintf(tmp_str,"ÅÒ¤±¶â (1-%ld)¡©", (long int)maxbet); #else - sprintf(tmp_str,"Your wager (1-%ld) ? ", maxbet); + sprintf(tmp_str,"Your wager (1-%ld) ? ", (long int)maxbet); #endif diff --git a/src/cmd3.c b/src/cmd3.c index e9b19f9e5..ec784a592 100644 --- a/src/cmd3.c +++ b/src/cmd3.c @@ -47,12 +47,11 @@ void do_cmd_inven(void) #ifdef JP sprintf(out_val, "»ý¤Áʪ¡§ ¹ç·× %3d.%1d kg (¸Â³¦¤Î%ld%%) ¥³¥Þ¥ó¥É: ", lbtokg1(p_ptr->total_weight) , lbtokg2(p_ptr->total_weight) , - (p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) -/ 2)); + ((long int)p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2)); #else sprintf(out_val, "Inventory: carrying %d.%d pounds (%ld%% of capacity). Command: ", (int)(p_ptr->total_weight / 10), (int)(p_ptr->total_weight % 10), - (p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2)); + ((long int)p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2)); #endif @@ -122,12 +121,11 @@ void do_cmd_equip(void) #ifdef JP sprintf(out_val, "ÁõÈ÷¡§ ¹ç·× %3d.%1d kg (¸Â³¦¤Î%ld%%) ¥³¥Þ¥ó¥É: ", lbtokg1(p_ptr->total_weight) , lbtokg2(p_ptr->total_weight) , - (p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) -/ 2)); + ((long int)p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2)); #else sprintf(out_val, "Equipment: carrying %d.%d pounds (%ld%% of capacity). Command: ", (int)(p_ptr->total_weight / 10), (int)(p_ptr->total_weight % 10), - (p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2)); + ((long int)p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2)); #endif diff --git a/src/cmd4.c b/src/cmd4.c index 9fa04a318..d6a960661 100644 --- a/src/cmd4.c +++ b/src/cmd4.c @@ -7021,7 +7021,7 @@ static void do_cmd_knowledge_kill_count(void) char file_name[1024]; - s32b Total = 0; + long Total = 0; /* Open a new file */ diff --git a/src/files.c b/src/files.c index 77422cfee..5b5a8e240 100644 --- a/src/files.c +++ b/src/files.c @@ -4546,7 +4546,7 @@ errr make_character_dump(FILE *fff) /* Monsters slain */ { int k; - s32b Total = 0; + long Total = 0; for (k = 1; k < max_r_idx; k++) { @@ -4586,9 +4586,9 @@ errr make_character_dump(FILE *fff) else #ifdef JP - fprintf(fff,"\n %lu ÂΤÎŨ¤òÅݤ·¤Æ¤¤¤Þ¤¹¡£\n", Total); + fprintf(fff,"\n %ld ÂΤÎŨ¤òÅݤ·¤Æ¤¤¤Þ¤¹¡£\n", Total); #else - fprintf(fff,"\n You have defeated %lu enemies.\n", Total); + fprintf(fff,"\n You have defeated %ld enemies.\n", Total); #endif } diff --git a/src/spells2.c b/src/spells2.c index e2b71e511..ac3fb0ff9 100644 --- a/src/spells2.c +++ b/src/spells2.c @@ -109,9 +109,9 @@ sprintf(Dummy, " info[i++] = ""; #ifdef JP - sprintf(Dummy, "¸½ºß¤Î°À­ : %s(%ld)", your_alignment(), p_ptr->align); + sprintf(Dummy, "¸½ºß¤Î°À­ : %s(%ld)", your_alignment(), (long int)p_ptr->align); #else - sprintf(Dummy, "Your alighnment : %s(%ld)", your_alignment(), p_ptr->align); + sprintf(Dummy, "Your alighnment : %s(%ld)", your_alignment(), (long int)p_ptr->align); #endif strcpy(buf[1], Dummy); info[i++] = buf[1]; diff --git a/src/wizard1.c b/src/wizard1.c index 48e0ea4ba..131245e71 100644 --- a/src/wizard1.c +++ b/src/wizard1.c @@ -1316,11 +1316,11 @@ static void analyze_misc(object_type *o_ptr, char *misc_desc) #ifdef JP sprintf(misc_desc, "¥ì¥Ù¥ë %u, ´õ¾¯ÅÙ %u, %d.%d kg, ¡ð%ld", a_ptr->level, a_ptr->rarity, - lbtokg1(a_ptr->weight), lbtokg2(a_ptr->weight), a_ptr->cost); + lbtokg1(a_ptr->weight), lbtokg2(a_ptr->weight), (long int)a_ptr->cost); #else sprintf(misc_desc, "Level %u, Rarity %u, %d.%d lbs, %ld Gold", a_ptr->level, a_ptr->rarity, - a_ptr->weight / 10, a_ptr->weight % 10, a_ptr->cost); + a_ptr->weight / 10, a_ptr->weight % 10, (long int)a_ptr->cost); #endif } diff --git a/src/wizard2.c b/src/wizard2.c index dc6d8e289..d6239c4d7 100644 --- a/src/wizard2.c +++ b/src/wizard2.c @@ -1049,7 +1049,7 @@ static void wiz_statistics(object_type *o_ptr) break; } - sprintf(tmp_val, "%ld", test_roll); + sprintf(tmp_val, "%ld", (long int)test_roll); if (get_string(p, tmp_val, 10)) test_roll = atol(tmp_val); test_roll = MAX(1, test_roll); -- 2.11.0