MCPcopy Create free account
hub / github.com/AOMediaCodec/libavif / avifArrayPush

Function avifArrayPush

src/utils.c:108–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108void * avifArrayPush(void * arrayStruct)
109{
110 avifArrayInternal * arr = (avifArrayInternal *)arrayStruct;
111 if (arr->count == arr->capacity) {
112 uint8_t * oldPtr = arr->ptr;
113 size_t oldByteCount = (size_t)arr->elementSize * arr->capacity;
114 if (oldByteCount > SIZE_MAX / 2 || arr->capacity > UINT32_MAX / 2) {
115 return NULL;
116 }
117 size_t newByteCount = oldByteCount * 2;
118 uint8_t * newPtr = (uint8_t *)avifAlloc(newByteCount);
119 if (newPtr == NULL) {
120 return NULL;
121 }
122 arr->ptr = newPtr;
123 memset(arr->ptr + oldByteCount, 0, oldByteCount);
124 memcpy(arr->ptr, oldPtr, oldByteCount);
125 arr->capacity *= 2;
126 avifFree(oldPtr);
127 }
128 ++arr->count;
129 return &arr->ptr[(arr->count - 1) * (size_t)arr->elementSize];
130}
131
132void avifArrayPop(void * arrayStruct)
133{

Calls 2

avifAllocFunction · 0.85
avifFreeFunction · 0.85

Tested by

no test coverage detected