| 2285 | } |
| 2286 | |
| 2287 | int av_opt_set_array(void *obj, const char *name, int search_flags, |
| 2288 | unsigned int start_elem, unsigned int nb_elems, |
| 2289 | enum AVOptionType val_type, const void *val) |
| 2290 | { |
| 2291 | const size_t elem_size_val = opt_type_desc[TYPE_BASE(val_type)].size; |
| 2292 | |
| 2293 | const AVOption *o; |
| 2294 | const AVOptionArrayDef *arr; |
| 2295 | void *target_obj; |
| 2296 | |
| 2297 | void *parray; |
| 2298 | void *new_elems; |
| 2299 | unsigned *array_size, new_size; |
| 2300 | size_t elem_size; |
| 2301 | |
| 2302 | int ret = 0; |
| 2303 | |
| 2304 | ret = opt_set_init(obj, name, search_flags, 0, &target_obj, &o, &parray); |
| 2305 | if (ret < 0) |
| 2306 | return ret; |
| 2307 | |
| 2308 | if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY) || |
| 2309 | (val_type & AV_OPT_TYPE_FLAG_ARRAY)) |
| 2310 | return AVERROR(EINVAL); |
| 2311 | |
| 2312 | arr = o->default_val.arr; |
| 2313 | array_size = opt_array_pcount(parray); |
| 2314 | elem_size = opt_type_desc[TYPE_BASE(o->type)].size; |
| 2315 | |
| 2316 | if (start_elem > *array_size) |
| 2317 | return AVERROR(EINVAL); |
| 2318 | |
| 2319 | // compute new array size |
| 2320 | if (!val) { |
| 2321 | if (*array_size - start_elem < nb_elems) |
| 2322 | return AVERROR(EINVAL); |
| 2323 | |
| 2324 | new_size = *array_size - nb_elems; |
| 2325 | } else if (search_flags & AV_OPT_ARRAY_REPLACE) { |
| 2326 | if (start_elem >= UINT_MAX - nb_elems) |
| 2327 | return AVERROR(EINVAL); |
| 2328 | |
| 2329 | new_size = FFMAX(*array_size, start_elem + nb_elems); |
| 2330 | } else { |
| 2331 | if (nb_elems >= UINT_MAX - *array_size) |
| 2332 | return AVERROR(EINVAL); |
| 2333 | |
| 2334 | new_size = *array_size + nb_elems; |
| 2335 | } |
| 2336 | |
| 2337 | if (arr && |
| 2338 | ((arr->size_max && new_size > arr->size_max) || |
| 2339 | (arr->size_min && new_size < arr->size_min))) |
| 2340 | return AVERROR(EINVAL); |
| 2341 | |
| 2342 | // desired operation is shrinking the array |
| 2343 | if (!val) { |
| 2344 | void *array = *(void**)parray; |
no test coverage detected