From 343b2376c0e39890fd5917207dd1a1ec697d4550 Mon Sep 17 00:00:00 2001 From: Nicolas Tsiftes Date: Tue, 10 Jan 2012 11:38:33 +0100 Subject: [PATCH] Use variable-length arrays instead of alloca. --- apps/antelope/index-inline.c | 14 +++++--------- apps/antelope/relation.c | 10 ++++------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/apps/antelope/index-inline.c b/apps/antelope/index-inline.c index 2654ce5b5..24527ee50 100644 --- a/apps/antelope/index-inline.c +++ b/apps/antelope/index-inline.c @@ -32,8 +32,8 @@ * A binary search index for attributes that are constrained to be * monotonically increasing, which is a rather common pattern for * time series or keys. Since this index has no storage overhead, - * it does not wear out the flash memory nor does it occupy scarce - * scarce space. Furthermore, unlike B+-trees, it has a O(1) memory + * it does not wear out the flash memory nor does it occupy any + * space. Furthermore, unlike B+-trees, it has a O(1) memory * footprint in relation to the number of data items. * \author * Nicolas Tsiftes @@ -85,14 +85,9 @@ index_api_t index_inline = { static attribute_value_t * get_value(tuple_id_t *index, relation_t *rel, attribute_t *attr) { - unsigned char *row; + unsigned char row[rel->row_length]; static attribute_value_t value; - row = alloca(rel->row_length); - if(row == NULL) { - return NULL; - } - if(DB_ERROR(storage_get_row(rel, index, row))) { return NULL; } @@ -142,7 +137,8 @@ binary_search(index_iterator_t *index_iterator, } else { max = center - 1; } - } while(min <= max && db_value_to_long(target_value) != db_value_to_long(cmp_value)); + } while(min <= max && + db_value_to_long(target_value) != db_value_to_long(cmp_value)); if(exact_match && db_value_to_long(target_value) != db_value_to_long(cmp_value)) { diff --git a/apps/antelope/relation.c b/apps/antelope/relation.c index 6576f01ca..d28fddb19 100644 --- a/apps/antelope/relation.c +++ b/apps/antelope/relation.c @@ -475,19 +475,17 @@ relation_remove(char *name, int remove_tuples) db_result_t relation_insert(relation_t *rel, attribute_value_t *values) { - size_t size; attribute_t *attr; - storage_row_t record; + unsigned char record[rel->row_length]; unsigned char *ptr; attribute_value_t *value; db_result_t result; value = values; - size = rel->row_length; - PRINTF("DB: Relation %s has a record size of %d bytes\n", - rel->name, (int)size); - ptr = record = alloca(size); + PRINTF("DB: Relation %s has a record size of %u bytes\n", + rel->name, (unsigned)rel->row_length); + ptr = record; PRINTF("DB: Insert (");