/** * Advance the BDD iterator, taking into account that some assignments * need to be expanded twice. */ static void advance_assignment(struct ipset_iterator *iterator) { /* Check the current state of the iterator to determine how to * advance. */ /* In most cases, the assignment we just finished only needed to be * expanded once. So we move on to the next assignment and process * it. */ if (CORK_LIKELY(iterator->multiple_expansion_state == IPSET_ITERATOR_NORMAL)) { ipset_bdd_iterator_advance(iterator->bdd_iterator); process_assignment(iterator); return; } /* If the assignment needs to be expanded twice, we'll do the IPv4 * expansion first. If that's what we've just finished, do the IPv6 * expansion next. */ if (iterator->multiple_expansion_state == IPSET_ITERATOR_MULTIPLE_IPV4) { DEBUG("Expanding IPv6 second"); iterator->multiple_expansion_state = IPSET_ITERATOR_MULTIPLE_IPV6; ipset_assignment_set (iterator->bdd_iterator->assignment, 0, IPSET_FALSE); expand_ipv6(iterator); return; } /* If we've just finished the IPv6 expansion, then we've finished * with this assignment. Before moving on to the next one, we have * to reset variable 0 to EITHER (which it was before we started * this whole mess). */ if (iterator->multiple_expansion_state == IPSET_ITERATOR_MULTIPLE_IPV6) { DEBUG("Finished both expansions"); ipset_assignment_set (iterator->bdd_iterator->assignment, 0, IPSET_EITHER); ipset_bdd_iterator_advance(iterator->bdd_iterator); process_assignment(iterator); return; } }
static void cork_buffer_ensure_size_int(struct cork_buffer *buffer, size_t desired_size) { size_t new_size; if (CORK_LIKELY(buffer->allocated_size >= desired_size)) { return; } /* Make sure we at least double the old size when reallocating. */ new_size = buffer->allocated_size * 2; if (desired_size > new_size) { new_size = desired_size; } buffer->buf = cork_realloc(buffer->buf, buffer->allocated_size, new_size); buffer->allocated_size = new_size; }