From 9bd0f184391329bb1fc9a83df2e273480833ef5d Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 18 Nov 2015 22:10:50 +0100 Subject: [PATCH] Replace assertions with more informative messages --- cmdline/elem.c | 27 +++++++++++++++++++++++++-- cmdline/elem.h | 7 +------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/cmdline/elem.c b/cmdline/elem.c index 5772e3ac..331bc942 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -607,8 +607,18 @@ struct snapraid_chunk* chunk_alloc(block_off_t parity_pos, struct snapraid_file* { struct snapraid_chunk* chunk; - assert(count != 0); - assert(file_pos + count <= file->blockmax); + if (count == 0) { + /* LCOV_EXCL_START */ + log_fatal("Internal inconsistency when allocating empty chunk for file '%s' at position '%u/%u'\n", file->sub, file_pos, file->blockmax); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + if (file_pos + count > file->blockmax) { + /* LCOV_EXCL_START */ + log_fatal("Internal inconsistency when allocating overflowing chunk for file '%s' at position '%u:%u/%u'\n", file->sub, file_pos, count, file->blockmax); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } chunk = malloc_nofail(sizeof(struct snapraid_chunk)); chunk->parity_pos = parity_pos; @@ -1272,6 +1282,19 @@ void fs_deallocate(struct snapraid_disk* disk, block_off_t parity_pos) disk->fs_last = second_chunk; } +struct snapraid_block* fs_file2block_get(struct snapraid_file* file, block_off_t file_pos) +{ + if (file_pos >= file->blockmax) { + /* LCOV_EXCL_START */ + log_fatal("Internal inconsistency when dereferencing file '%s' at position '%u/%u'\n", file->sub, file_pos, file->blockmax); + abort(); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + + return &file->blockvec[file_pos]; +} + struct snapraid_block* fs_par2block_get_ts(struct snapraid_disk* disk, struct snapraid_chunk** fs_last, block_off_t parity_pos) { struct snapraid_file* file; diff --git a/cmdline/elem.h b/cmdline/elem.h index 89fe45ad..28873c08 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -915,12 +915,7 @@ void fs_deallocate(struct snapraid_disk* disk, block_off_t pos); /** * Get the block from the file position. */ -static inline struct snapraid_block* fs_file2block_get(struct snapraid_file* file, block_off_t file_pos) -{ - assert(file_pos < file->blockmax); - - return &file->blockvec[file_pos]; -} +struct snapraid_block* fs_file2block_get(struct snapraid_file* file, block_off_t file_pos); /** * Like fs_file2par_get() but thread-safe.