[ext2resize] [PATCH] Endless loop in ext2_move_blocks()?
Status: Inactive
Brought to you by:
adilger
From: Petter R. <pe...@hu...> - 2006-03-16 07:21:24
|
When building ext2resize 1.1.19 with -W and -Wall, I see this warning: ext2.c: I funktionen 'ext2_move_blocks': ext2.c:137: advarsel: comparison of unsigned expression >= 0 is always true This is the code in question: blk_t i; [...] } else if (src > dest) for (i = 0; i < num; i++) ext2_copy_block(fs, src + i, dest + i); else for (i = num - 1; i >= 0; i--) ext2_copy_block(fs, src + i, dest + i); As i is unsigned, it will always be 0 or higher, and this the else block is an endless loop. What is the best way to fix this? My suggestion is to run i from num to 0 instead of trying to run from num-1 to -1: --- ext2resize-1.1.19.orig/src/ext2.c +++ ext2resize-1.1.19/src/ext2.c @@ -131,8 +131,8 @@ for (i = 0; i < num; i++) ext2_copy_block(fs, src + i, dest + i); else - for (i = num - 1; i >= 0; i--) - ext2_copy_block(fs, src + i, dest + i); + for (i = num; i > 0; i--) + ext2_copy_block(fs, src + i - 1, dest + i - 1); } void ext2_read_blocks(struct ext2_fs *fs, void *ptr, blk_t block, blk_t num) Can the default build be changed to include -W in addition to -Wall? It show quite a lot of signed/unsigned issues, and I suspect it is better to expose those to more people. I suggest adding code like this to configure.in just before the "dnl Checks for libraries." line. if eval "test x$GCC = xyes"; then CFLAGS="$CFLAGS -W -Wall" fi Friendly, -- Petter Reinholdtsen |