Skip to content

Commit 05624b5

Browse files
Merge pull request #6856 from MjnMixael/fix_get_mod_root_name
Prevent string ops on nullptr char*
2 parents 9b82dae + 8be619d commit 05624b5

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

code/scripting/api/libs/base.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,14 @@ ADE_FUNC(getVersionString, l_Base, nullptr,
667667
}
668668

669669
ADE_FUNC(getModRootName, l_Base, nullptr,
670-
"Returns the name of the current mod's root folder.", "string", "The mod root")
670+
"Returns the name of the current mod's root folder.", "string", "The mod root or empty string if the mod runs without a -mod line")
671671
{
672-
SCP_string str = Cmdline_mod;
672+
const char* mod = Cmdline_mod;
673+
if (mod == nullptr) {
674+
mod = "";
675+
}
676+
677+
SCP_string str = mod;
673678

674679
// Trim any trailing folders so we get just the name of the root mod folder
675680
str = str.substr(0, str.find_first_of(DIR_SEPARATOR_CHAR));

0 commit comments

Comments
 (0)