summaryrefslogtreecommitdiff
path: root/src/array.c
diff options
context:
space:
mode:
authorArno Töll <arno@debian.org>2012-11-21 23:03:59 +0100
committerArno Töll <arno@debian.org>2012-11-21 23:03:59 +0100
commit16cadaab87d25fc026ac777746eabbff3030f0cc (patch)
treeebd408dc2d6d5d821137994e93203e57ab8f25f6 /src/array.c
parent985230456afb0b945234dfac919a6ece3df4a715 (diff)
downloadlighttpd-16cadaab87d25fc026ac777746eabbff3030f0cc.tar.gz
Imported Upstream version 1.4.28upstream/1.4.28
Diffstat (limited to 'src/array.c')
-rw-r--r--src/array.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/array.c b/src/array.c
index e93906b..05568b3 100644
--- a/src/array.c
+++ b/src/array.c
@@ -130,20 +130,21 @@ data_unset *array_get_element(array *a, const char *key) {
data_unset *array_get_unused_element(array *a, data_type_t t) {
data_unset *ds = NULL;
+ unsigned int i;
- UNUSED(t);
+ for (i = a->used; i < a->size; i++) {
+ if (a->data[i] && a->data[i]->type == t) {
+ ds = a->data[i];
- if (a->size == 0) return NULL;
+ /* make empty slot at a->used for next insert */
+ a->data[i] = a->data[a->used];
+ a->data[a->used] = NULL;
- if (a->used == a->size) return NULL;
-
- if (a->data[a->used]) {
- ds = a->data[a->used];
-
- a->data[a->used] = NULL;
+ return ds;
+ }
}
- return ds;
+ return NULL;
}
void array_set_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len) {
@@ -194,7 +195,7 @@ int array_insert_unique(array *a, data_unset *str) {
if (a->data[ndx]->type == str->type) {
str->insert_dup(a->data[ndx], str);
} else {
- fprintf(stderr, "a\n");
+ SEGFAULT();
}
return 0;
}
@@ -224,6 +225,9 @@ int array_insert_unique(array *a, data_unset *str) {
ndx = (int) a->used;
+ /* make sure there is nothing here */
+ if (a->data[ndx]) a->data[ndx]->free(a->data[ndx]);
+
a->data[a->used++] = str;
if (pos != ndx &&