| 108 | /* grows internal buffer to satisfy required minimal capacity */ |
| 109 | |
| 110 | static void stack_grow(ACL_STACK *s, int min_capacity) |
| 111 | { |
| 112 | const char *myname = "stack_grow"; |
| 113 | const char *ptr; |
| 114 | int min_delta = 16; |
| 115 | int delta; |
| 116 | |
| 117 | /* don't need to grow the capacity of the array */ |
| 118 | if (s->capacity >= min_capacity) |
| 119 | return; |
| 120 | delta = min_capacity; |
| 121 | /* make delta a multiple of min_delta */ |
| 122 | delta += min_delta - 1; |
| 123 | delta /= min_delta; |
| 124 | delta *= min_delta; |
| 125 | /* actual grow */ |
| 126 | if (delta <= 0) |
| 127 | return; |
| 128 | s->capacity += delta; |
| 129 | if (s->items) { |
| 130 | s->items = (void **) acl_default_realloc(__FILE__, __LINE__, |
| 131 | s->items, s->capacity * sizeof(void *)); |
| 132 | ptr = "realloc"; |
| 133 | } else { |
| 134 | s->items = (void **) acl_default_malloc(__FILE__, __LINE__, |
| 135 | s->capacity * sizeof(void *)); |
| 136 | ptr = "malloc"; |
| 137 | } |
| 138 | |
| 139 | if (s->items == NULL) { |
| 140 | char ebuf[256]; |
| 141 | acl_msg_fatal("%s(%d): %s error(%s)", |
| 142 | myname, __LINE__, ptr, |
| 143 | acl_last_strerror(ebuf, sizeof(ebuf))); |
| 144 | } |
| 145 | |
| 146 | /* reset, just in case */ |
| 147 | memset(s->items + s->count, 0, (s->capacity - s->count) * sizeof(void *)); |
| 148 | } |
| 149 | |
| 150 | /* if you are going to append a known and large number of items, call this first */ |
| 151 |
no test coverage detected
searching dependent graphs…