On error, this function must set arr->ptr to NULL and both arr->count and arr->capacity to 0.
| 85 | |
| 86 | // On error, this function must set arr->ptr to NULL and both arr->count and arr->capacity to 0. |
| 87 | avifBool avifArrayCreate(void * arrayStruct, uint32_t elementSize, uint32_t initialCapacity) |
| 88 | { |
| 89 | avifArrayInternal * arr = (avifArrayInternal *)arrayStruct; |
| 90 | arr->elementSize = elementSize ? elementSize : 1; |
| 91 | arr->count = 0; |
| 92 | arr->capacity = initialCapacity; |
| 93 | if (arr->capacity > SIZE_MAX / arr->elementSize) { |
| 94 | arr->ptr = NULL; |
| 95 | arr->capacity = 0; |
| 96 | return AVIF_FALSE; |
| 97 | } |
| 98 | size_t byteCount = (size_t)arr->elementSize * arr->capacity; |
| 99 | arr->ptr = (uint8_t *)avifAlloc(byteCount); |
| 100 | if (!arr->ptr) { |
| 101 | arr->capacity = 0; |
| 102 | return AVIF_FALSE; |
| 103 | } |
| 104 | memset(arr->ptr, 0, byteCount); |
| 105 | return AVIF_TRUE; |
| 106 | } |
| 107 | |
| 108 | void * avifArrayPush(void * arrayStruct) |
| 109 | { |
no test coverage detected