From 190d0e29c962d4a6dc1f8bcac8e4571146a2e810 Mon Sep 17 00:00:00 2001 From: Jan Cybulski Date: Tue, 28 Jan 2014 13:50:02 +0100 Subject: [PATCH] libsmack: add possibility of resizing table of labels Signed-off-by: Jan Cybulski --- libsmack/libsmack.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libsmack/libsmack.c b/libsmack/libsmack.c index bd68af7..79ae822 100644 --- a/libsmack/libsmack.c +++ b/libsmack/libsmack.c @@ -90,6 +90,7 @@ struct smack_accesses { int labels_cnt; struct smack_rule *first; struct smack_rule *last; + int labels_alloc; struct smack_label **labels; struct smack_hash_entry *label_hash; }; @@ -125,7 +126,8 @@ int smack_accesses_new(struct smack_accesses **accesses) result = calloc(1, sizeof(struct smack_accesses)); if (result == NULL) return -1; - result->labels = malloc(DICT_HASH_SIZE * sizeof(struct smack_label *)); + result->labels_alloc = 128; + result->labels = malloc(128 * sizeof(struct smack_label *)); if (result->labels == NULL) goto err_out; result->label_hash = calloc(DICT_HASH_SIZE, sizeof(struct smack_hash_entry)); @@ -875,15 +877,23 @@ static struct smack_label *label_add(struct smack_accesses *handle, const char * struct smack_label *new_label; int len; - if (handle->labels_cnt == DICT_HASH_SIZE) - return NULL; - len = get_label(NULL, label, &hash_value); if (len == -1) return NULL; new_label = is_label_known(handle, label, hash_value); if (new_label == NULL) {/*no entry added yet*/ + if (handle->labels_cnt == handle->labels_alloc) { + struct smack_label **new_labels; + int size = handle->labels_alloc * 2 * sizeof(struct smack_label *); + new_labels = realloc(handle->labels, size); + if (new_labels != NULL) { + handle->labels = new_labels; + handle->labels_alloc *= 2; + } else + return NULL; + } + new_label = malloc(sizeof(struct smack_label)); if (new_label == NULL) return NULL; -- 2.7.4