32 |
|
void *statgrab_vector_resize(void *vector, vector_header *h, int count) { |
33 |
|
int new_count, i; |
34 |
|
|
35 |
< |
/* Destroy any now-unused items. */ |
35 |
> |
/* Destroy any now-unused items. |
36 |
> |
* |
37 |
> |
* Note that there's an assumption here that making the vector smaller |
38 |
> |
* will never fail; if it did, then we would have destroyed items here |
39 |
> |
* but not actually got rid of the vector pointing to them before the |
40 |
> |
* error return.) */ |
41 |
|
if (count < h->used_count && h->destroy_fn != NULL) { |
42 |
|
for (i = count; i < h->used_count; i++) { |
43 |
|
h->destroy_fn((void *) (vector + i * h->item_size)); |
56 |
|
if (new_vector == NULL && new_count != 0) { |
57 |
|
/* Out of memory -- free the contents of the vector. */ |
58 |
|
statgrab_vector_resize(vector, h, 0); |
59 |
< |
/* And return the sentinel value to indicate failure. */ |
60 |
< |
return statgrab_vector_sentinel; |
59 |
> |
h->error = -1; |
60 |
> |
return vector; |
61 |
|
} |
62 |
|
|
63 |
|
vector = new_vector; |
72 |
|
} |
73 |
|
|
74 |
|
h->used_count = count; |
75 |
< |
|
75 |
> |
h->error = 0; |
76 |
|
return vector; |
77 |
|
} |
78 |
|
|