//static U8* LLVFile::readFile(LLVFS *vfs, LLPrivateMemoryPool* poolp, const LLUUID &uuid, LLAssetType::EType type, S32* bytes_read) { U8 *data; LLVFile file(vfs, uuid, type, LLVFile::READ); S32 file_size = file.getSize(); if (file_size == 0) { // File is empty. data = NULL; } else { data = (U8*)ALLOCATE_MEM(poolp, file_size); file.read(data, file_size); /* Flawfinder: ignore */ if (file.getLastBytesRead() != (S32)file_size) { FREE_MEM(poolp, data); data = NULL; file_size = 0; } } if (bytes_read) { *bytes_read = file_size; } return data; }
// virtual U8* LLImageBase::allocateData(S32 size) { LLMemType mt1(mMemType); if (size < 0) { size = mWidth * mHeight * mComponents; if (size <= 0) { llerrs << llformat("LLImageBase::allocateData called with bad dimensions: %dx%dx%d",mWidth,mHeight,(S32)mComponents) << llendl; } } else if (size <= 0 || (size > 4096*4096*16 && !mAllowOverSize)) { llerrs << "LLImageBase::allocateData: bad size: " << size << llendl; } if (!mData || size != mDataSize) { deleteData(); // virtual mBadBufferAllocation = false ; mData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); if (!mData) { llwarns << "allocate image data: " << size << llendl; size = 0 ; mWidth = mHeight = 0 ; mBadBufferAllocation = true ; } mDataSize = size; } return mData; }
// virtual U8* LLImageBase::allocateData(S32 size) { if (size < 0) { size = mWidth * mHeight * mComponents; if (size <= 0) { LL_WARNS() << llformat("LLImageBase::allocateData called with bad dimensions: %dx%dx%d",mWidth,mHeight,(S32)mComponents) << LL_ENDL; return NULL; } } //make this function thread-safe. static const U32 MAX_BUFFER_SIZE = 4096 * 4096 * 16 ; //256 MB if (size < 1 || size > MAX_BUFFER_SIZE) { LL_INFOS() << "width: " << mWidth << " height: " << mHeight << " components: " << mComponents << LL_ENDL ; if(mAllowOverSize) { LL_INFOS() << "Oversize: " << size << LL_ENDL ; } else { LL_WARNS() << "LLImageBase::allocateData: bad size: " << size << LL_ENDL; return NULL; } } if (!mData || size != mDataSize) { deleteData(); // virtual mBadBufferAllocation = false ; mData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); if (!mData) { LL_WARNS() << "Failed to allocate image data, size: " << size << " width: " << mWidth << " height: " << mHeight << LL_ENDL; size = 0 ; mWidth = mHeight = 0 ; mBadBufferAllocation = true ; addAllocationError(); } mDataSize = size; claimMem(mDataSize); } return mData; }
// virtual U8* LLImageBase::allocateData(S32 size) { LLMemType mt1(mMemType); if (size < 0) { size = mWidth * mHeight * mComponents; if (size <= 0) { llerrs << llformat("LLImageBase::allocateData called with bad dimensions: %dx%dx%d",mWidth,mHeight,(S32)mComponents) << llendl; } } //make this function thread-safe. static const U32 MAX_BUFFER_SIZE = 4096 * 4096 * 16 ; //256 MB if (size < 1 || size > MAX_BUFFER_SIZE) { llinfos << "width: " << mWidth << " height: " << mHeight << " components: " << mComponents << llendl ; if(mAllowOverSize) { llinfos << "Oversize: " << size << llendl ; } else { llerrs << "LLImageBase::allocateData: bad size: " << size << llendl; } } if (!mData || size != mDataSize) { deleteData(); // virtual mBadBufferAllocation = false ; mData = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); if (!mData) { llwarns << "Failed to allocate image data size [" << size << "]" << llendl; size = 0 ; mWidth = mHeight = 0 ; mBadBufferAllocation = true ; } mDataSize = size; } return mData; }
// virtual U8* LLImageBase::reallocateData(S32 size) { LLMemType mt1(mMemType); U8 *new_datap = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); if (!new_datap) { llwarns << "Out of memory in LLImageBase::reallocateData" << llendl; return 0; } if (mData) { S32 bytes = llmin(mDataSize, size); memcpy(new_datap, mData, bytes); /* Flawfinder: ignore */ FREE_MEM(sPrivatePoolp, mData) ; } mData = new_datap; mDataSize = size; return mData; }
// virtual U8* LLImageBase::reallocateData(S32 size) { U8 *new_datap = (U8*)ALLOCATE_MEM(sPrivatePoolp, size); if (!new_datap) { LL_WARNS() << "Out of memory in LLImageBase::reallocateData, size: " << size << LL_ENDL; return 0; } if (mData) { S32 bytes = llmin(mDataSize, size); memcpy(new_datap, mData, bytes); /* Flawfinder: ignore */ FREE_MEM(sPrivatePoolp, mData) ; } mData = new_datap; disclaimMem(mDataSize); mDataSize = size; claimMem(mDataSize); return mData; }