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

Function CheckArray

NULLC/Executor_Common.cpp:255–317  ·  view source on GitHub ↗

Function that checks arrays for pointers

Source from the content-addressed store, hash-verified

253
254 // Function that checks arrays for pointers
255 void CheckArray(char* ptr, const ExternTypeInfo& type)
256 {
257 // Get array element type
258 ExternTypeInfo *subType = type.nameHash == autoArrayName ? NULL : &NULLC::commonLinker->exTypes[type.subType];
259 // Real array size (changed for unsized arrays)
260 unsigned int size = type.arrSize;
261 // If array type is an unsized array, check pointer that points to actual array contents
262 if(type.arrSize == TypeInfo::UNSIZED_ARRAY)
263 {
264 // Get real array size
265 size = *(int*)(ptr + NULLC_PTR_SIZE);
266 // Switch pointer to array data
267 char **rPtr = (char**)ptr;
268 ptr = *rPtr;
269 // If uninitialized or points to stack memory, return
270 if(!ptr || ptr <= (char*)0x00010000 || (ptr >= unmanageableBase && ptr <= unmanageableTop))
271 return;
272 GC_DEBUG_PRINT("\tGlobal pointer %p\r\n", ptr);
273 // Get base pointer
274 unsigned int *basePtr = (unsigned int*)NULLC::GetBasePointer(ptr);
275 markerType *marker = (markerType*)((char*)basePtr - sizeof(markerType));
276 // If there is no base pointer or memory already marked, exit
277 if(!basePtr || (*marker & 1))
278 return;
279 // Mark memory as used
280 *marker |= 1;
281 }else if(type.nameHash == autoArrayName){
282 NULLCAutoArray *data = (NULLCAutoArray*)ptr;
283 // Get real variable type
284 subType = &NULLC::commonLinker->exTypes[data->typeID];
285 // skip uninitialized array
286 if(!data->ptr)
287 return;
288 // Mark target data
289 MarkPointer((char*)&data->ptr, *subType, false);
290 // Switch pointer to target
291 ptr = data->ptr;
292 // Get array size
293 size = data->len;
294 }
295 if(!subType->pointerCount)
296 return;
297 // Otherwise, check every array element is it's either array, pointer of class
298 switch(subType->subCat)
299 {
300 case ExternTypeInfo::CAT_ARRAY:
301 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
302 CheckArray(ptr, *subType);
303 break;
304 case ExternTypeInfo::CAT_POINTER:
305 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
306 MarkPointer(ptr, *subType, true);
307 break;
308 case ExternTypeInfo::CAT_CLASS:
309 for(unsigned int i = 0; i < size; i++, ptr += subType->size)
310 CheckClass(ptr, *subType);
311 break;
312 case ExternTypeInfo::CAT_FUNCTION:

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