MCPcopy Create free account
hub / github.com/WheretIB/nullc / CheckArray

Function CheckArray

NULLC/translation/runtime.cpp:865–924  ·  view source on GitHub ↗

Function that checks arrays for pointers

Source from the content-addressed store, hash-verified

863
864 // Function that checks arrays for pointers
865 void CheckArray(char* ptr, const NULLCTypeInfo& type)
866 {
867 // Get array element type
868 NULLCTypeInfo *subType = type.hash == autoArrayName ? NULL : &__nullcTypeList[type.subTypeID];
869 // Real array size (changed for unsized arrays)
870 unsigned int size = type.memberCount;
871 // If array type is an unsized array, check pointer that points to actual array contents
872 if(size == -1)
873 {
874 // Get real array size
875 size = ((NULLCArray<void>*)ptr)->size;
876 // Switch pointer to array data
877 char **rPtr = (char**)ptr;
878 ptr = *rPtr;
879 // If uninitialized or points to stack memory, return
880 if(!ptr || ptr <= (char*)0x00010000 || (ptr >= unmanageableBase && ptr <= unmanageableTop))
881 return;
882 GC_DEBUG_PRINT("\tGlobal pointer %p\r\n", ptr);
883 // Get base pointer
884 unsigned int *basePtr = (unsigned int*)NULLC::GetBasePointer(ptr);
885 // If there is no base pointer or memory already marked, exit
886 if(!basePtr || (*((unsigned int*)(basePtr) - 1) & 0xff))
887 return;
888 // Mark memory as used
889 *((unsigned int*)(basePtr) - 1) |= 1;
890 }else if(type.hash == autoArrayName){
891 NULLCAutoArray *data = (NULLCAutoArray*)ptr;
892 // Get real variable type
893 subType = &__nullcTypeList[data->typeID];
894 // skip uninitialized array
895 if(!data->ptr)
896 return;
897 // Mark target data
898 MarkPointer((char*)&data->ptr, *subType, false);
899 // Switch pointer to target
900 ptr = data->ptr;
901 // Get array size
902 size = data->len;
903 }
904 // Otherwise, check every array element is it's either array, pointer of class
905 switch(subType->category)
906 {
907 case NULLC_ARRAY:
908 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
909 CheckArray(ptr, *subType);
910 break;
911 case NULLC_POINTER:
912 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
913 MarkPointer(ptr, *subType, true);
914 break;
915 case NULLC_CLASS:
916 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
917 CheckClass(ptr, *subType);
918 break;
919 case NULLC_FUNCTION:
920 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
921 CheckFunction(ptr);
922 break;

Callers 2

CheckClassFunction · 0.70
CheckVariableFunction · 0.70

Calls 3

MarkPointerFunction · 0.70
CheckClassFunction · 0.70
CheckFunctionFunction · 0.70

Tested by

no test coverage detected