static dd_bool Reader_Check(Reader1 const *reader, size_t len) { #ifdef DENG_WRITER_TYPECHECK // One byte for the code. if (len) len++; #endif DENG_ASSERT(reader); DENG_ASSERT(reader->data || reader->useCustomFuncs); if (!reader || (!reader->data && !reader->useCustomFuncs)) return false; if (reader->useCustomFuncs) { // Not our responsibility. return true; } if (reader->pos > reader->size - len) { App_Log(DE2_LOG_ERROR, "Reader_Check: Position %lu[+%lu] out of bounds, size=%lu.", (unsigned long) reader->pos, (unsigned long) len, (unsigned long) reader->size); App_FatalError("Reader1 bounds check failed."); } return true; }
void Str_Delete(Str *str) { if(!str) return; DENG_ASSERT(!Garbage_IsTrashed(str)); #if 0 // use this is release builds if encountering Str/AutoStr errors if(Garbage_IsTrashed(str)) { App_FatalError("Str_Delete: Trying to manually delete an AutoStr!"); } #endif deleteString(str); }
void Z_CheckHeap(void) { memvolume_t *volume; memblock_t *block; dd_bool isDone; App_Log(DE2_LOG_TRACE, "Z_CheckHeap"); lockZone(); for (volume = volumeRoot; volume; volume = volume->next) { size_t total = 0; // Validate the counter. if (allocatedMemoryInVolume(volume) != volume->allocatedBytes) { App_Log(DE2_LOG_CRITICAL, "Z_CheckHeap: allocated bytes counter is off (counter:%u != actual:%u)", volume->allocatedBytes, allocatedMemoryInVolume(volume)); App_FatalError("Z_CheckHeap: zone book-keeping is wrong"); } // Does the memory in the blocks sum up to the total volume size? for (block = volume->zone->blockList.next; block != &volume->zone->blockList; block = block->next) { total += block->size; } if (total != volume->size - sizeof(memzone_t)) { App_Log(DE2_LOG_CRITICAL, "Z_CheckHeap: invalid total size of blocks (%u != %u)", total, volume->size - sizeof(memzone_t)); App_FatalError("Z_CheckHeap: zone book-keeping is wrong"); } // Does the last block extend all the way to the end? block = volume->zone->blockList.prev; if ((byte *)block - ((byte *)volume->zone + sizeof(memzone_t)) + block->size != volume->size - sizeof(memzone_t)) { App_Log(DE2_LOG_CRITICAL, "Z_CheckHeap: last block does not cover the end (%u != %u)", (byte *)block - ((byte *)volume->zone + sizeof(memzone_t)) + block->size, volume->size - sizeof(memzone_t)); App_FatalError("Z_CheckHeap: zone is corrupted"); } block = volume->zone->blockList.next; isDone = false; while (!isDone) { if (block->next != &volume->zone->blockList) { if (block->size == 0) App_FatalError("Z_CheckHeap: zero-size block"); if ((byte *) block + block->size != (byte *) block->next) App_FatalError("Z_CheckHeap: block size does not touch the " "next block"); if (block->next->prev != block) App_FatalError("Z_CheckHeap: next block doesn't have proper " "back link"); if (!block->user && !block->next->user) App_FatalError("Z_CheckHeap: two consecutive free blocks"); if (block->user == (void **) -1) { DENG_ASSERT(block->user != (void **) -1); App_FatalError("Z_CheckHeap: bad user pointer"); } /* if (block->seqFirst == block) { // This is the first. printf("sequence begins at (%p): start=%p, end=%p\n", block, block->seqFirst, block->seqLast); } */ if (block->seqFirst) { //printf(" seq member (%p): start=%p\n", block, block->seqFirst); if (block->seqFirst->seqLast == block) { //printf(" -=- last member of seq %p -=-\n", block->seqFirst); } else { if (block->next->seqFirst != block->seqFirst) { App_FatalError("Z_CheckHeap: disconnected sequence"); } } } block = block->next; } else isDone = true; // all blocks have been hit } } unlockZone(); }