From: Andre Noll Date: Sat, 16 May 2020 16:28:03 +0000 (+0200) Subject: Activate -Wsign-compare. X-Git-Tag: v0.2.0~3^2 X-Git-Url: http://git.tuebingen.mpg.de/?p=osl.git;a=commitdiff_plain;h=576fe981b1c21595f2b04c2b69153dc0a46dbfdf Activate -Wsign-compare. Currently this option is disabled but the number of warnings it triggers is moderate. This patch fixes all of them and enables the warning. --- diff --git a/Makefile b/Makefile index 76ab5eb..bdf78a2 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ VERSION := $(x).$(y).$(z) OSL_CPPFLAGS += -DOSL_VERSION='"$(VERSION)"' -OSL_CFLAGS += -Wno-sign-compare -g -Wunused -Wundef -W +OSL_CFLAGS += -g -Wunused -Wundef -W OSL_CFLAGS += -Wredundant-decls OSL_CFLAGS += -Os OSL_CFLAGS += -Wall diff --git a/fsck.c b/fsck.c index f96f77c..e814df5 100644 --- a/fsck.c +++ b/fsck.c @@ -393,24 +393,25 @@ static int fsck_mark_row_invalid(struct osl_table *t, int i) */ static int check_index_ranges(struct osl_table *t) { - int i, j, ret; + int ret; + unsigned k, n; INFO_LOG("checking for range violations in index\n"); //DEBUG_LOG("%d rows. %d columns\n", t->num_rows, t->desc->num_columns); t->num_invalid_rows = 0; - for (i = 0; i < t->num_rows; i++) { + for (n = 0; n < t->num_rows; n++) { const struct osl_column_description *cd; - if (row_is_invalid(t, i)) { + if (row_is_invalid(t, n)) { t->num_invalid_rows++; continue; } - FOR_EACH_MAPPED_COLUMN(j, t, cd) { - ret = check_range(t, i, j); + FOR_EACH_MAPPED_COLUMN(k, t, cd) { + ret = check_range(t, n, k); if (ret < 0) { if (ret != -E_FSCK_RANGE_VIOLATION) goto err; - ret = fsck_mark_row_invalid(t, i); + ret = fsck_mark_row_invalid(t, n); if (ret < 0) goto err; t->num_invalid_rows++; @@ -505,29 +506,30 @@ static int prune_invalid_rows_from_index(struct osl_table *t) static int check_for_invalid_objects(struct osl_table *t, uint32_t **lost_bytes) { - int i, j, ret; + int ret; + unsigned k, n; const struct osl_column_description *cd; uint32_t *loss = fsck_malloc(sizeof(uint32_t) * t->desc->num_columns); INFO_LOG("looking for mapped objects not contained in index\n"); /* first count used bytes */ - FOR_EACH_MAPPED_COLUMN(i, t, cd) { - loss[i] = t->columns[i].data_map.size; - DEBUG_LOG("column %i data map: %zu bytes\n", i, - t->columns[i].data_map.size); - for (j = 0; j < t->num_rows; j++) { + FOR_EACH_MAPPED_COLUMN(k, t, cd) { + loss[k] = t->columns[k].data_map.size; + DEBUG_LOG("column %i data map: %zu bytes\n", k, + t->columns[k].data_map.size); + for (n = 0; n < t->num_rows; n++) { struct osl_object obj; - ret = get_mapped_object(t, i, j, &obj); + ret = get_mapped_object(t, k, n, &obj); if (ret < 0) goto err; - loss[i] -= obj.size; + loss[k] -= obj.size; } } ret = 0; - FOR_EACH_MAPPED_COLUMN(i, t, cd) { - if (loss[i]) { + FOR_EACH_MAPPED_COLUMN(k, t, cd) { + if (loss[k]) { NOTICE_LOG("column %u contains %u lost bytes\n", - i, loss[i]); + k, loss[k]); ret = 1; } } @@ -543,24 +545,25 @@ err: /* prune_invalid_rows() must be run on the table before calling this */ static int prune_mapped_column(struct osl_table *t, uint32_t col_num, int fd) { - int i, ret; + int ret; + unsigned n; uint32_t written = 0; struct osl_column *col = t->columns + col_num; INFO_LOG("pruning col %u\n", col_num); - for (i = 0; i < t->num_rows; i++) { + for (n = 0; n < t->num_rows; n++) { struct osl_object obj; char *index_entry; - DEBUG_LOG("checking row %u/%u\n", i, t->num_rows); - ret = get_mapped_object(t, col_num, i, &obj); + DEBUG_LOG("checking row %u/%u\n", n, t->num_rows); + ret = get_mapped_object(t, col_num, n, &obj); if (ret < 0) return ret; ret = _write_all(fd, (char *)(obj.data), obj.size); if (ret < 0) return ret; written += obj.size; - ret = get_row_index(t, i, &index_entry); + ret = get_row_index(t, n, &index_entry); if (ret < 0) return ret; update_cell_index(index_entry, col, written, obj.size); @@ -702,7 +705,8 @@ out: static int check_disk_storage_presence(struct osl_table *t) { - int ret, i, j; + int ret; + unsigned k, n; struct osl_object obj, hash_obj = {.size = HASH_SIZE}; char *ds_name; const struct osl_column_description *cd; @@ -712,18 +716,18 @@ static int check_disk_storage_presence(struct osl_table *t) return 1; hashes = fsck_malloc(t->num_rows * HASH_SIZE); INFO_LOG("looking for missing disk storage objects\n"); - for (i = 0; i < t->num_rows; i++) { - if (row_is_invalid(t, i)) + for (k = 0; k < t->num_rows; k++) { + if (row_is_invalid(t, k)) continue; - ret = get_mapped_object(t, dsnc, i, &obj); + ret = get_mapped_object(t, dsnc, k, &obj); if (ret < 0) return ret; - hash_object(&obj, hashes + i * HASH_SIZE); - hash_obj.data = hashes + i * HASH_SIZE; + hash_object(&obj, hashes + k * HASH_SIZE); + hash_obj.data = hashes + k * HASH_SIZE; osl_add_row(hash_tree_table, &hash_obj); - ds_name = disk_storage_name_of_hash(t, hashes + i * HASH_SIZE); - FOR_EACH_DISK_STORAGE_COLUMN(j, t, cd) { - ret = check_disk_storage_column(t, i, j, ds_name, + ds_name = disk_storage_name_of_hash(t, hashes + k * HASH_SIZE); + FOR_EACH_DISK_STORAGE_COLUMN(n, t, cd) { + ret = check_disk_storage_column(t, k, n, ds_name, &missing_objects); if (ret < 0) goto err; @@ -1223,7 +1227,8 @@ static int check_all_tables(const char *db_dir) int main(int argc, char **argv) { - int i, ret; + int ret; + unsigned n; char *errctx = NULL; const char *dd; @@ -1265,8 +1270,8 @@ int main(int argc, char **argv) ret = check_all_tables(dd); goto out; } - for (i = 0; i < lls_num_inputs(lpr); i++) { - ret = check_table(dd, lls_input(i, lpr)); + for (n = 0; n < lls_num_inputs(lpr); n++) { + ret = check_table(dd, lls_input(n, lpr)); if (ret < 0) break; } diff --git a/osl.c b/osl.c index e31811b..17bddeb 100644 --- a/osl.c +++ b/osl.c @@ -1002,12 +1002,13 @@ __export int osl_close_table(struct osl_table *t, enum osl_close_flags flags) int row_is_invalid(struct osl_table *t, uint32_t row_num) { char *row_index; - int i, ret = get_row_index(t, row_num, &row_index); + int ret = get_row_index(t, row_num, &row_index); + unsigned n; if (ret < 0) return ret; - for (i = 0; i < t->row_index_size; i++) { - if ((unsigned char)row_index[i] != 0xff) + for (n = 0; n < t->row_index_size; n++) { + if ((unsigned char)row_index[n] != 0xff) return 0; } INFO_LOG("row %d is invalid\n", row_num); @@ -1046,17 +1047,18 @@ int mark_row_invalid(struct osl_table *t, uint32_t row_num) */ int init_rbtrees(struct osl_table *t) { - int i, ret; + int ret; + unsigned n; const struct osl_column_description *cd; /* create rbtrees */ - FOR_EACH_RBTREE_COLUMN(i, t, cd) - t->columns[i].rbtree = RB_ROOT; + FOR_EACH_RBTREE_COLUMN(n, t, cd) + t->columns[n].rbtree = RB_ROOT; /* add valid rows to rbtrees */ t->num_invalid_rows = 0; - for (i = 0; i < t->num_rows; i++) { + for (n = 0; n < t->num_rows; n++) { struct osl_object *volatile_objs; - ret = row_is_invalid(t, i); + ret = row_is_invalid(t, n); if (ret < 0) return ret; if (ret) { @@ -1070,7 +1072,7 @@ int init_rbtrees(struct osl_table *t) return -E_OSL_NOMEM; } else volatile_objs = NULL; - ret = add_row_to_rbtrees(t, i, volatile_objs, NULL); + ret = add_row_to_rbtrees(t, n, volatile_objs, NULL); if (ret < 0) return ret; } diff --git a/osl_core.h b/osl_core.h index 6046d8c..bdc584b 100644 --- a/osl_core.h +++ b/osl_core.h @@ -363,8 +363,8 @@ _static_inline_ char *disk_storage_path(const struct osl_table *t, * \sa FOR_EACH_COLUMN_OF_TYPE, FOR_EACH_MAPPED_COLUMN, FOR_EACH_RBTREE_COLUMN, * FOR_EACH_DISK_STORAGE_COLUMN, FOR_EACH_VOLATILE_COLUMN, osl_storage_type. */ -_static_inline_ int next_column_of_type(enum osl_storage_type type, int col_num, - const struct osl_table *t, +_static_inline_ unsigned next_column_of_type(enum osl_storage_type type, + unsigned col_num, const struct osl_table *t, const struct osl_column_description **cd) { *cd = NULL; diff --git a/sha1.c b/sha1.c index 3346d76..e10ccca 100644 --- a/sha1.c +++ b/sha1.c @@ -249,13 +249,13 @@ static void blk_SHA1_Init(blk_SHA_CTX *ctx) static void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len) { - int lenW = ctx->size & 63; + unsigned lenW = ctx->size & 63; ctx->size += len; /* Read the data into W and process blocks as they get full */ if (lenW) { - int left = 64 - lenW; + unsigned left = 64 - lenW; if (len < left) left = len; memcpy(lenW + (char *)ctx->W, data, left); diff --git a/util.c b/util.c index 32f3402..34667e3 100644 --- a/util.c +++ b/util.c @@ -229,7 +229,7 @@ __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...) n = vsnprintf(p, size, fmt, ap); va_end(ap); /* If that worked, return the string. */ - if (n > -1 && n < size) + if (n > -1 && (unsigned)n < size) break; /* Else try again with more space. */ if (n > -1) /* glibc 2.1 */