Skip to content

Commit

Permalink
fix(core): add safe static var for ios static crash
Browse files Browse the repository at this point in the history
  • Loading branch information
etkmao committed Sep 26, 2024
1 parent fe4ac69 commit 8c8691e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/footstone/include/footstone/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class SafeStaticVar {
template<typename T>
static void InitSafeStaticVar(SafeStaticVar<T> *var, std::shared_ptr<T> &var_inner) {
var->var_inner_ = var_inner;
uint64_t *p = (uint64_t *)&var_inner;
uint64_t *p = (uint64_t *)&var->var_inner_;
uint64_t value = *p;
value ^= 0xf;
var->sign_before_ = value;
var->sign_after_ = value;
}
Expand All @@ -65,6 +66,10 @@ template<typename T>
static std::shared_ptr<T> GetSafeStaticVar(SafeStaticVar<T> *var) {
uint64_t *p = (uint64_t *)&var->var_inner_;
uint64_t value = *p;
if (value == 0) {
return nullptr;
}
value ^= 0xf;
if (var->sign_before_ != value) {
return nullptr;
}
Expand Down

0 comments on commit 8c8691e

Please sign in to comment.