From e984e914b6aced5dabe250ad769c63186f21f8b8 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Sun, 23 Dec 2012 15:14:08 -0500 Subject: Make CLANG happy Address CLANG issues in the main code. --- collection/collection.c | 2 +- collection/collection_ut.c | 11 +++++++++++ dhash/dhash.c | 9 +++++++-- path_utils/path_utils.c | 12 ++++-------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/collection/collection.c b/collection/collection.c index ce0bbec..d836aa4 100644 --- a/collection/collection.c +++ b/collection/collection.c @@ -574,7 +574,7 @@ int col_insert_item_into_current(struct collection_item *collection, /* Move to the right position counting */ while (idx > 0) { idx--; - parent = parent->next; + if (parent->next) parent = parent->next; } item->next = parent->next; parent->next = item; diff --git a/collection/collection_ut.c b/collection/collection_ut.c index abf0f11..1b48fc0 100644 --- a/collection/collection_ut.c +++ b/collection/collection_ut.c @@ -1354,6 +1354,9 @@ int insert_extract_test(void) (error = col_insert_str_property(col, NULL, COL_DSP_END, NULL, 0, COL_INSERT_NOCHECK, "property1", "value1", 0)) || + (error = col_insert_str_property(col, NULL, COL_DSP_INDEX, + NULL, 1, COL_INSERT_NOCHECK, + "second", "second", 0)) || (error = col_insert_str_property(col, NULL, COL_DSP_END, NULL, 0, COL_INSERT_NOCHECK, "property2", "value2", 0)) || @@ -1437,6 +1440,14 @@ int insert_extract_test(void) ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT))) || + (error = col_extract_item(col, NULL, COL_DSP_FRONT, + NULL, 0, 0, &item)) || + + (error = col_insert_item(col2, NULL, item, COL_DSP_FRONT, + NULL, 0, COL_INSERT_NOCHECK)) || + + ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT))) || + (error = col_extract_item(col, NULL, COL_DSP_END, NULL, 0, 0, &item)) || diff --git a/dhash/dhash.c b/dhash/dhash.c index 79f9c38..efd7c8d 100644 --- a/dhash/dhash.c +++ b/dhash/dhash.c @@ -888,12 +888,17 @@ int hash_get_default(hash_table_t *table, hash_key_t *key, hash_value_t *value, if (!table) return HASH_ERROR_BAD_TABLE; - if ((error = hash_lookup(table, key, value)) != HASH_SUCCESS) { - if ((error = hash_enter(table, key, default_value)) != HASH_SUCCESS) { + error = hash_lookup(table, key, value); + if (error == HASH_ERROR_KEY_NOT_FOUND) { + + error = hash_enter(table, key, default_value); + if (error != HASH_SUCCESS) { return error; } *value = *default_value; return HASH_SUCCESS; + } else { + if (error != HASH_SUCCESS) return error; } return HASH_SUCCESS; diff --git a/path_utils/path_utils.c b/path_utils/path_utils.c index 0a758c5..a9ae7b3 100644 --- a/path_utils/path_utils.c +++ b/path_utils/path_utils.c @@ -357,13 +357,13 @@ char **split_path(const char *path, int *count) for (start = end = path; *start; start = end) { for (start = end; *start && *start == '/'; start++); for (end = start; *end && *end != '/'; end++); - if ((component_len = end - start) == 0) break; + if ((end - start) == 0) break; *array_ptr++ = component_ptr; while (start < end) *component_ptr++ = *start++; *component_ptr++ = 0; } - *array_ptr++ = NULL; + *array_ptr = NULL; if (count) *count = n_components; return (char **)mem_block; } @@ -565,7 +565,7 @@ int directory_list(const char *path, bool recursive, } for (entry = readdir(dir); entry; entry = readdir(dir)) { - prune = false; + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { continue; @@ -611,25 +611,21 @@ bool is_ancestor_path(const char *ancestor, const char *path) { char **path_components, **ancestor_components; int i, path_count, ancestor_count; - bool result; + bool result = false; - result = false; path_components = split_path(path, &path_count); ancestor_components = split_path(ancestor, &ancestor_count); if (!path_components || !ancestor_components) { - result = false; goto exit; } if (ancestor_count >= path_count) { - result = false; goto exit; } for (i = 0; i < ancestor_count; i++) { if (strcmp(path_components[i], ancestor_components[i]) != 0) { - result = false; goto exit; } } -- cgit