Skip to content

Commit b76e652

Browse files
authored
Merge pull request scp-fs2open#7282 from Goober5000/const_char_lookup
assorted `const` fixes
2 parents f01eec9 + a47d34c commit b76e652

File tree

11 files changed

+21
-25
lines changed

11 files changed

+21
-25
lines changed

code/ai/ai_profiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ void ai_profiles_init()
812812
Ai_profiles_initted = 1;
813813
}
814814

815-
int ai_profile_lookup(char *name)
815+
int ai_profile_lookup(const char *name)
816816
{
817817
for (int i = 0; i < Num_ai_profiles; i++)
818818
if (!stricmp(name, Ai_profiles[i].profile_name))

code/ai/ai_profiles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ extern ai_profile_t Ai_profiles[MAX_AI_PROFILES];
164164

165165
void ai_profiles_init();
166166

167-
int ai_profile_lookup(char *name);
167+
int ai_profile_lookup(const char *name);
168168

169169
#endif

code/graphics/software/NVGFont.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace font
3232
return 1;
3333
}
3434

35-
const char *nullPtr = strchr(const_cast<char*>(string), '\0');
36-
const char *nextToken = strpbrk(const_cast<char*>(string), TOKEN_SEPARATORS);
35+
const char *nullPtr = strchr(string, '\0');
36+
const char *nextToken = strpbrk(string, TOKEN_SEPARATORS);
3737

3838
// WOHOO! Pointer arithmetic!!!
3939
if (nullPtr != NULL && (nextToken == NULL || nullPtr < nextToken))

code/lab/dialogs/lab_ui.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ static void build_ship_table_info_txtbox(ship_info* sip)
660660
}
661661

662662
InputTextMultiline("##table_text",
663-
const_cast<char*>(table_text.c_str()),
663+
table_text.data(),
664664
table_text.length(),
665665
ImVec2(-FLT_MIN, GetTextLineHeight() * 16),
666666
ImGuiInputTextFlags_ReadOnly);
@@ -681,7 +681,7 @@ static void build_weapon_table_info_txtbox(weapon_info* wip)
681681
}
682682

683683
InputTextMultiline("##weapon_table_text",
684-
const_cast<char*>(table_text.c_str()),
684+
table_text.data(),
685685
table_text.length(),
686686
ImVec2(-FLT_MIN, GetTextLineHeight() * 16),
687687
ImGuiInputTextFlags_ReadOnly);
@@ -1506,7 +1506,7 @@ void LabUi::show_object_options() const
15061506
}
15071507

15081508
InputTextMultiline("##asteroid_table_text",
1509-
const_cast<char*>(table_text.c_str()),
1509+
table_text.data(),
15101510
table_text.length(),
15111511
ImVec2(-FLT_MIN, GetTextLineHeight() * 16),
15121512
ImGuiInputTextFlags_ReadOnly);
@@ -1544,7 +1544,7 @@ void LabUi::show_object_options() const
15441544
}
15451545

15461546
InputTextMultiline("##prop_table_text",
1547-
const_cast<char*>(table_text.c_str()),
1547+
table_text.data(),
15481548
table_text.length(),
15491549
ImVec2(-FLT_MIN, GetTextLineHeight() * 16),
15501550
ImGuiInputTextFlags_ReadOnly);

code/missioneditor/campaignsave.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ typedef struct campaign_link {
88
int node; // node tracker when link is in sexp tree window
99
bool is_mission_loop; // whether link leads to mission loop
1010
bool is_mission_fork; // whether link leads to mission fork
11-
char* mission_branch_txt; // text describing mission loop
12-
char* mission_branch_brief_anim; // filename of anim to play in the brief
13-
char* mission_branch_brief_sound; // filename of anim to play in the brief
11+
const char* mission_branch_txt; // text describing mission loop
12+
const char* mission_branch_brief_anim; // filename of anim to play in the brief
13+
const char* mission_branch_brief_sound; // filename of anim to play in the brief
1414
} campaign_link;
1515

1616
class Fred_campaign_save : public Fred_mission_save {

code/network/multi_xfer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ int multi_xfer_get_flags(int handle)
450450
}
451451

452452
// if the passed filename is being xferred, return the xfer handle, otherwise return -1
453-
int multi_xfer_lookup(char *filename)
453+
int multi_xfer_lookup(const char *filename)
454454
{
455455
int idx;
456456

code/network/multi_xfer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void multi_xfer_xor_flags(int handle,int flags);
8787
int multi_xfer_get_flags(int handle);
8888

8989
// if the passed filename is being xferred, return the xfer handle, otherwise return -1
90-
int multi_xfer_lookup(char *filename);
90+
int multi_xfer_lookup(const char *filename);
9191

9292
// get the % of completion of the passed file handle, return < 0 if invalid
9393
float multi_xfer_pct_complete(int handle);

code/scripting/api/libs/graphics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ ADE_INDEXER(l_Graphics_Posteffects, "number index", "Gets the name of the specif
185185
if (index >= (int) names.size())
186186
return ade_set_error(L, "s", "");
187187

188-
return ade_set_args(L, "s", const_cast<char*>(names[index].c_str()));
188+
return ade_set_args(L, "s", names[index].c_str());
189189
}
190190

191191
ADE_FUNC(__len, l_Graphics_Posteffects, nullptr, "Gets the number of available post-processing effects", "number", "number of post-processing effects or 0 on error")

freespace2/freespace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7553,7 +7553,7 @@ int detect_lang()
75537553

75547554
// try and open the file to verify
75557555
font::stuff_first(first_font);
7556-
CFILE *detect = cfopen(const_cast<char*>(first_font.c_str()), "rb");
7556+
CFILE *detect = cfopen(first_font.c_str(), "rb");
75577557

75587558
// will use default setting if something went wrong
75597559
if (!detect)

qtfred/src/mission/dialogs/CampaignEditorDialogModel.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,9 @@ void CampaignEditorDialogModel::saveCampaign(const SCP_string& filename)
507507

508508
// The descriptive text fields only apply to special (loop/fork) branches.
509509
if (branch.is_loop || branch.is_fork) {
510-
link.mission_branch_txt =
511-
branch.loop_description.empty() ? nullptr : const_cast<char*>(branch.loop_description.c_str());
512-
link.mission_branch_brief_anim =
513-
branch.loop_briefing_anim.empty() ? nullptr : const_cast<char*>(branch.loop_briefing_anim.c_str());
514-
link.mission_branch_brief_sound = branch.loop_briefing_sound.empty()
515-
? nullptr
516-
: const_cast<char*>(branch.loop_briefing_sound.c_str());
510+
link.mission_branch_txt = branch.loop_description.empty() ? nullptr : branch.loop_description.c_str();
511+
link.mission_branch_brief_anim = branch.loop_briefing_anim.empty() ? nullptr : branch.loop_briefing_anim.c_str();
512+
link.mission_branch_brief_sound = branch.loop_briefing_sound.empty() ? nullptr : branch.loop_briefing_sound.c_str();
517513
} else {
518514
link.mission_branch_txt = nullptr;
519515
link.mission_branch_brief_anim = nullptr;

0 commit comments

Comments
 (0)