mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-10 09:40:53 +01:00
Change OC_STRING_ASSIGN_N macro to function to fix a side effect.
This commit is contained in:
parent
9d7d7b6059
commit
e6c194d1b9
@ -103,20 +103,41 @@ OcMain (
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#define OC_STRING_ASSIGN_N(ocString, value, len) do { \
|
||||
if( len >= sizeof(ocString.Value) ) { \
|
||||
memset(ocString.Value, 0, sizeof(ocString.Value)); \
|
||||
ocString.DynValue = (__typeof__(ocString.DynValue))malloc(len); \
|
||||
memcpy(ocString.DynValue, value, len); \
|
||||
ocString.MaxSize = (UINT32)len; \
|
||||
ocString.Size = (UINT32)len; /* unsafe cast */ \
|
||||
}else{ \
|
||||
ocString.DynValue = NULL; \
|
||||
memcpy(ocString.Value, value, len); \
|
||||
ocString.MaxSize = sizeof(ocString.Value); \
|
||||
ocString.Size = (UINT32)len; /* unsafe cast */ \
|
||||
} \
|
||||
} while (0)
|
||||
// This was a macro.
|
||||
// But there is a catch : if parameter value depends on ocString.DynValue, DynValue is wiped before value is evaluated.
|
||||
// Solution could have been an intermediary variable.
|
||||
inline void OC_DATA_ASSIGN_N(OC_DATA& ocString, const unsigned char* value, size_t len) {
|
||||
if( len >= sizeof(ocString.Value) ) {
|
||||
memset(ocString.Value, 0, sizeof(ocString.Value));
|
||||
ocString.DynValue = (__typeof__(ocString.DynValue))malloc(len);
|
||||
memcpy(ocString.DynValue, value, len);
|
||||
ocString.MaxSize = (UINT32)len;
|
||||
ocString.Size = (UINT32)len; /* unsafe cast */
|
||||
}else{
|
||||
ocString.DynValue = NULL;
|
||||
memcpy(ocString.Value, value, len);
|
||||
ocString.MaxSize = sizeof(ocString.Value);
|
||||
ocString.Size = (UINT32)len; /* unsafe cast */
|
||||
}
|
||||
}
|
||||
|
||||
// This was a macro.
|
||||
// But there is a catch : if parameter value depends on ocString.DynValue, DynValue is wiped before value is evaluated.
|
||||
// Solution could have been an intermediary variable.
|
||||
inline void OC_STRING_ASSIGN_N(OC_STRING& ocString, const char* value, size_t len) {
|
||||
if( len >= sizeof(ocString.Value) ) {
|
||||
memset(ocString.Value, 0, sizeof(ocString.Value));
|
||||
ocString.DynValue = (__typeof__(ocString.DynValue))malloc(len);
|
||||
memcpy(ocString.DynValue, value, len);
|
||||
ocString.MaxSize = (UINT32)len;
|
||||
ocString.Size = (UINT32)len; /* unsafe cast */
|
||||
}else{
|
||||
ocString.DynValue = NULL;
|
||||
memcpy(ocString.Value, value, len);
|
||||
ocString.MaxSize = sizeof(ocString.Value);
|
||||
ocString.Size = (UINT32)len; /* unsafe cast */
|
||||
}
|
||||
}
|
||||
|
||||
#define OC_STRING_ASSIGN(ocString, value) OC_STRING_ASSIGN_N(ocString, value, strlen(value)+1)
|
||||
|
||||
|
@ -739,14 +739,14 @@ void LOADER_ENTRY::DelegateKernelPatches()
|
||||
mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Count = (UINT32)kextPatch.Count;
|
||||
mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Enabled = 1;
|
||||
|
||||
OC_STRING_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Find, kextPatch.Find.data(), kextPatch.Find.size());
|
||||
OC_DATA_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Find, kextPatch.Find.data(), kextPatch.Find.size());
|
||||
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Identifier, kextPatch.getName().c_str());
|
||||
mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Limit = (UINT32)kextPatch.SearchLen;
|
||||
OC_STRING_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Mask, kextPatch.MaskFind.vdata(), kextPatch.MaskFind.size());
|
||||
OC_DATA_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Mask, kextPatch.MaskFind.data(), kextPatch.MaskFind.size());
|
||||
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->MaxKernel, ""); // it has been filtered, so we don't need to set Min and MaxKernel
|
||||
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->MinKernel, "");
|
||||
OC_STRING_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Replace, kextPatch.Replace.vdata(), kextPatch.Replace.size());
|
||||
OC_STRING_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->ReplaceMask, kextPatch.MaskReplace.vdata(), kextPatch.MaskReplace.size());
|
||||
OC_DATA_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Replace, kextPatch.Replace.data(), kextPatch.Replace.size());
|
||||
OC_DATA_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->ReplaceMask, kextPatch.MaskReplace.data(), kextPatch.MaskReplace.size());
|
||||
mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Skip = (UINT32)kextPatch.Skip;
|
||||
#ifdef JIEF_DEBUG
|
||||
if ( kextPatch.Label == "algrey - cpuid_set_info - ryzen cores and logicals count - part 3 - 10.14"_XS8 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user