| 365 |
365 |
| 366 // corner case |
366 // corner case |
| 367 if (elem_count == 0) return 0; |
367 if (elem_count == 0) return 0; |
| 368 |
368 |
| 369 // overflow check |
369 // overflow check |
| |
370 // LCOV_EXCL_START |
| 370 if (elem_count > SIZE_MAX - *size) { |
371 if (elem_count > SIZE_MAX - *size) { |
| 371 errno = EOVERFLOW; |
372 errno = EOVERFLOW; |
| 372 return 1; |
373 return 1; |
| 373 } |
374 } |
| |
375 // LCOV_EXCL_STOP |
| 374 |
376 |
| 375 // store some counts |
377 // store some counts |
| 376 const size_t old_size = *size; |
378 const size_t old_size = *size; |
| 377 const size_t old_capacity = *capacity; |
379 const size_t old_capacity = *capacity; |
| 378 // the necessary capacity is the worst case assumption, including duplicates |
380 // the necessary capacity is the worst case assumption, including duplicates |
| 790 if (cxReallocateArray( |
792 if (cxReallocateArray( |
| 791 list->collection.allocator, |
793 list->collection.allocator, |
| 792 &arl->data, new_capacity, |
794 &arl->data, new_capacity, |
| 793 list->collection.elem_size) |
795 list->collection.elem_size) |
| 794 ) { |
796 ) { |
| 795 return 0; |
797 return 0; // LCOV_EXCL_LINE |
| 796 } |
798 } |
| 797 arl->capacity = new_capacity; |
799 arl->capacity = new_capacity; |
| 798 } |
800 } |
| 799 |
801 |
| 800 // determine insert position |
802 // determine insert position |
| 886 ) { |
888 ) { |
| 887 struct cx_list_s *list = iter->src_handle; |
889 struct cx_list_s *list = iter->src_handle; |
| 888 if (iter->index < list->collection.size) { |
890 if (iter->index < list->collection.size) { |
| 889 if (cx_arl_insert_element(list, |
891 if (cx_arl_insert_element(list, |
| 890 iter->index + 1 - prepend, elem) == NULL) { |
892 iter->index + 1 - prepend, elem) == NULL) { |
| 891 return 1; |
893 return 1; // LCOV_EXCL_LINE |
| 892 } |
894 } |
| 893 iter->elem_count++; |
895 iter->elem_count++; |
| 894 if (prepend != 0) { |
896 if (prepend != 0) { |
| 895 iter->index++; |
897 iter->index++; |
| 896 iter->elem_handle = ((char *) iter->elem_handle) + list->collection.elem_size; |
898 iter->elem_handle = ((char *) iter->elem_handle) + list->collection.elem_size; |
| 897 } |
899 } |
| 898 return 0; |
900 return 0; |
| 899 } else { |
901 } else { |
| 900 if (cx_arl_insert_element(list, list->collection.size, elem) == NULL) { |
902 if (cx_arl_insert_element(list, list->collection.size, elem) == NULL) { |
| 901 return 1; |
903 return 1; // LCOV_EXCL_LINE |
| 902 } |
904 } |
| 903 iter->elem_count++; |
905 iter->elem_count++; |
| 904 iter->index = list->collection.size; |
906 iter->index = list->collection.size; |
| 905 return 0; |
907 return 0; |
| 906 } |
908 } |