Skip to content

Commit

Permalink
C4Strings: Workaround libc++ bug (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fulgen301 committed Nov 19, 2024
1 parent 77ec33f commit d08a011
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/C4Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ bool C4Group::DeleteEntry(const char *szFilename, bool fRecycle)
case GRPF_Folder:
StdFile.Close();
char szPath[_MAX_FNAME + 1];
FormatWithNull(szPath, "{}" DirSep "{}", FileName, szFilename);
FormatWithNull(szPath, "{}" DirSep "{}", +FileName, szFilename);

if (fRecycle)
{
Expand Down Expand Up @@ -1781,7 +1781,7 @@ bool C4Group::ExtractEntry(const char *szFilename, const char *szExtractTo)
break;
case GRPF_Folder: // Copy item from folder to target
char szPath[_MAX_FNAME + 1];
FormatWithNull(szPath, "{}" DirSep "{}", FileName, szFilename);
FormatWithNull(szPath, "{}" DirSep "{}", +FileName, szFilename);
if (!CopyItem(szPath, szTargetFName))
return Error("ExtractEntry: Cannot copy item");
break;
Expand Down Expand Up @@ -2194,7 +2194,7 @@ uint32_t C4Group::EntryTime(const char *szFilename)
break;
case GRPF_Folder:
char szPath[_MAX_FNAME + 1];
FormatWithNull(szPath, "{}" DirSep "{}", FileName, szFilename);
FormatWithNull(szPath, "{}" DirSep "{}", +FileName, szFilename);
iTime = FileTime(szPath);
break;
}
Expand Down Expand Up @@ -2390,7 +2390,7 @@ bool C4Group::EnsureChildFilePtr(C4Group *pChild)

// Open standard file is not the child file ...or StdFile ptr does not match pChild->FilePtr
char szChildPath[_MAX_PATH + 1];
FormatWithNull(szChildPath, "{}" DirSep "{}", FileName, GetFilename(pChild->FileName));
FormatWithNull(szChildPath, "{}" DirSep "{}", +FileName, GetFilename(pChild->FileName));
if (!ItemIdentical(StdFile.Name, szChildPath))
{
// Reopen correct child stdfile
Expand Down
2 changes: 1 addition & 1 deletion src/C4Language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool C4Language::Init()
if (PackDirectory.Open(C4CFN_Languages))
while (PackDirectory.FindNextEntry("*.c4g", strEntry))
{
FormatWithNull(strPackFilename, "{}" DirSep "{}", C4CFN_Languages, strEntry);
FormatWithNull(strPackFilename, "{}" DirSep "{}", +C4CFN_Languages, +strEntry);
pPack = new C4Group();
if (pPack->Open(strPackFilename))
{
Expand Down
2 changes: 1 addition & 1 deletion src/C4Network2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ bool C4Network2::CreateDynamic(bool fInit)
Log(C4ResStrTableKey::IDS_NET_SAVING);
// compose file name
char szDynamicBase[_MAX_PATH + 1], szDynamicFilename[_MAX_PATH + 1];
FormatWithNull(szDynamicBase, "{}Dyn{}", Config.Network.WorkPath, GetFilename(Game.ScenarioFilename), _MAX_PATH);
FormatWithNull(szDynamicBase, "{}Dyn{}", +Config.Network.WorkPath, GetFilename(Game.ScenarioFilename), _MAX_PATH);
if (!ResList.FindTempResFileName(szDynamicBase, szDynamicFilename))
Log(C4ResStrTableKey::IDS_NET_SAVE_ERR_CREATEDYNFILE);
// save dynamic data
Expand Down
8 changes: 4 additions & 4 deletions src/C4ScriptHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ void C4DefScriptHost::AfterLink()
for (int32_t cnt = 0; cnt < Def->ActNum; cnt++)
{
C4ActionDef *pad = &Def->ActMap[cnt];
FormatWithNull(WhereStr, "Action {}: StartCall", pad->Name); pad->StartCall = GetSFuncWarn(pad->SStartCall, CallAccess, WhereStr);
FormatWithNull(WhereStr, "Action {}: PhaseCall", pad->Name); pad->PhaseCall = GetSFuncWarn(pad->SPhaseCall, CallAccess, WhereStr);
FormatWithNull(WhereStr, "Action {}: EndCall", pad->Name); pad->EndCall = GetSFuncWarn(pad->SEndCall, CallAccess, WhereStr);
FormatWithNull(WhereStr, "Action {}: AbortCall", pad->Name); pad->AbortCall = GetSFuncWarn(pad->SAbortCall, CallAccess, WhereStr);
FormatWithNull(WhereStr, "Action {}: StartCall", +pad->Name); pad->StartCall = GetSFuncWarn(pad->SStartCall, CallAccess, WhereStr);
FormatWithNull(WhereStr, "Action {}: PhaseCall", +pad->Name); pad->PhaseCall = GetSFuncWarn(pad->SPhaseCall, CallAccess, WhereStr);
FormatWithNull(WhereStr, "Action {}: EndCall", +pad->Name); pad->EndCall = GetSFuncWarn(pad->SEndCall, CallAccess, WhereStr);
FormatWithNull(WhereStr, "Action {}: AbortCall", +pad->Name); pad->AbortCall = GetSFuncWarn(pad->SAbortCall, CallAccess, WhereStr);
}
Def->TimerCall = GetSFuncWarn(Def->STimerCall, CallAccess, "TimerCall");
}
Expand Down
6 changes: 3 additions & 3 deletions src/C4Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,19 @@ struct C4NullableBasicStringView

using C4NullableStringView = C4NullableBasicStringView<char>;

template<std::size_t N, typename...Args>
template<std::size_t N, typename...Args> requires (!std::disjunction_v<std::is_array<std::remove_cvref_t<Args>>...>)
void FormatWithNull(char(&buf)[N], const std::format_string<Args...> fmt, Args&&...args)
{
*std::format_to_n(buf, N - 1, fmt, std::forward<Args>(args)...).out = '\0';
}

template<std::size_t N, typename...Args>
template<std::size_t N, typename...Args> requires (!std::disjunction_v<std::is_array<std::remove_cvref_t<Args>>...>)
void FormatWithNull(std::array<char, N> &buf, const std::format_string<Args...> fmt, Args&&...args)
{
*std::format_to_n(buf.begin(), N - 1, fmt, std::forward<Args>(args)...).out = '\0';
}

template<std::size_t N, typename... Args>
template<std::size_t N, typename... Args> requires (!std::disjunction_v<std::is_array<std::remove_cvref_t<Args>>...>)
void FormatWithNull(const std::span<char, N> buf, const std::format_string<Args...> fmt, Args &&...args)
{
*std::format_to_n(buf.begin(), buf.size() - 1, fmt, std::forward<Args>(args)...).out = '\0';
Expand Down

0 comments on commit d08a011

Please sign in to comment.