| 6709 | */ |
| 6710 | |
| 6711 | static _ipp_value_t * /* O - IPP value element or NULL on error */ |
| 6712 | ipp_set_value(ipp_t *ipp, /* IO - IPP message */ |
| 6713 | ipp_attribute_t **attr, /* IO - IPP attribute */ |
| 6714 | int element) /* I - Value number (0-based) */ |
| 6715 | { |
| 6716 | ipp_attribute_t *temp, /* New attribute pointer */ |
| 6717 | *current, /* Current attribute in list */ |
| 6718 | *prev; /* Previous attribute in list */ |
| 6719 | int alloc_values; /* Allocated values */ |
| 6720 | |
| 6721 | |
| 6722 | /* |
| 6723 | * If we are setting an existing value element, return it... |
| 6724 | */ |
| 6725 | |
| 6726 | temp = *attr; |
| 6727 | |
| 6728 | if (temp->num_values <= 1) |
| 6729 | alloc_values = 1; |
| 6730 | else |
| 6731 | alloc_values = (temp->num_values + IPP_MAX_VALUES - 1) & |
| 6732 | ~(IPP_MAX_VALUES - 1); |
| 6733 | |
| 6734 | if (element < alloc_values) |
| 6735 | { |
| 6736 | if (element >= temp->num_values) |
| 6737 | temp->num_values = element + 1; |
| 6738 | |
| 6739 | return (temp->values + element); |
| 6740 | } |
| 6741 | |
| 6742 | /* |
| 6743 | * Otherwise re-allocate the attribute - we allocate in groups of IPP_MAX_VALUE |
| 6744 | * values when num_values > 1. |
| 6745 | */ |
| 6746 | |
| 6747 | if (alloc_values < IPP_MAX_VALUES) |
| 6748 | alloc_values = IPP_MAX_VALUES; |
| 6749 | else |
| 6750 | alloc_values += IPP_MAX_VALUES; |
| 6751 | |
| 6752 | DEBUG_printf(("4ipp_set_value: Reallocating for up to %d values.", |
| 6753 | alloc_values)); |
| 6754 | |
| 6755 | /* |
| 6756 | * Reallocate memory... |
| 6757 | */ |
| 6758 | |
| 6759 | if ((temp = realloc(temp, sizeof(ipp_attribute_t) + (size_t)(alloc_values - 1) * sizeof(_ipp_value_t))) == NULL) |
| 6760 | { |
| 6761 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unable to reallocate IPP attribute value."), 1); |
| 6762 | DEBUG_puts("4ipp_set_value: Unable to resize attribute."); |
| 6763 | return (NULL); |
| 6764 | } |
| 6765 | |
| 6766 | /* |
| 6767 | * Zero the new memory... |
| 6768 | */ |
no test coverage detected