Skip to content

Commit 9162878

Browse files
committed
assorted const fixes
1. Change `ai_profile_lookup` and `multi_xfer_lookup` to use `const char *`, since all the other lookup functions do 2. Remove several unneeded `const_cast`s, some of which are now made possible by the non-const `data()` overload in C++17 3. Use better string management in `test::FSTestFixture::init_cmdline()`
1 parent 52081e2 commit 9162878

12 files changed

Lines changed: 20 additions & 20 deletions

File tree

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/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")

fred2/sexp_tree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3421,7 +3421,7 @@ int sexp_tree::get_default_value(sexp_list_item *item, char *text_buf, int op, i
34213421
break;
34223422

34233423
case OPF_FONT:
3424-
str = const_cast<char*>(font::FontManager::getFont(0)->getName().c_str());
3424+
str = font::FontManager::getFont(0)->getName().c_str();
34253425
break;
34263426

34273427
case OPF_AUDIO_VOLUME_OPTION:

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ void CampaignEditorDialogModel::saveCampaign(const SCP_string& filename)
508508
// The descriptive text fields only apply to special (loop/fork) branches.
509509
if (branch.is_loop || branch.is_fork) {
510510
link.mission_branch_txt =
511-
branch.loop_description.empty() ? nullptr : const_cast<char*>(branch.loop_description.c_str());
511+
branch.loop_description.empty() ? nullptr : branch.loop_description.data();
512512
link.mission_branch_brief_anim =
513-
branch.loop_briefing_anim.empty() ? nullptr : const_cast<char*>(branch.loop_briefing_anim.c_str());
513+
branch.loop_briefing_anim.empty() ? nullptr : branch.loop_briefing_anim.data();
514514
link.mission_branch_brief_sound = branch.loop_briefing_sound.empty()
515515
? nullptr
516-
: const_cast<char*>(branch.loop_briefing_sound.c_str());
516+
: branch.loop_briefing_sound.data();
517517
} else {
518518
link.mission_branch_txt = nullptr;
519519
link.mission_branch_brief_anim = nullptr;

0 commit comments

Comments
 (0)