Skip to content

Commit

Permalink
Logging: Prevent crash for nullptr strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Exzap committed Apr 2, 2024
1 parent fa8bab2 commit 3e467e2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Cafe/OS/common/OSUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ static std::tuple<Args...> cafeExportBuildArgTuple(PPCInterpreter_t* hCPU, R(fn)
return std::tuple<Args...>{ cafeExportGetParamWrapper<Args>(hCPU, gprIndex, fprIndex)... };
}

template<typename T>
T cafeExportGetFormatParamWrapper(PPCInterpreter_t* hCPU, int& gprIndex, int& fprIndex)
{
T v;
cafeExportParamWrapper::getParamWrapper(hCPU, gprIndex, fprIndex, v);
// if T is char* or const char*, return "null" instead of nullptr since newer fmtlib would throw otherwise
if constexpr (std::is_same_v<T, char*> || std::is_same_v<T, const char*>)
return v ? v : (T)"null";
return v;
}

template<typename T>
using _CAFE_FORMAT_ARG = std::conditional_t<std::is_pointer_v<T>,
std::conditional_t<std::is_same_v<T, char*> || std::is_same_v<T, const char*>, T, MEMPTR<T>>, T>;
Expand All @@ -150,7 +161,7 @@ static auto cafeExportBuildFormatTuple(PPCInterpreter_t* hCPU, R(fn)(Args...))
int gprIndex = 0;
int fprIndex = 0;
return std::tuple<_CAFE_FORMAT_ARG<Args>...>{
cafeExportGetParamWrapper<_CAFE_FORMAT_ARG<Args>>(hCPU, gprIndex, fprIndex)...
cafeExportGetFormatParamWrapper<_CAFE_FORMAT_ARG<Args>>(hCPU, gprIndex, fprIndex)...
};
}

Expand Down

0 comments on commit 3e467e2

Please sign in to comment.