e2fsck: remove unused variable 'new_array'
PATCH 1/4 e2fsck: remove unused variable 'new_array'
--- e2fsck/rehash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
e2fsck/rehash.c +1 -1
@@ -109,7 +109,7 @@ static int fill_dir_block(ext2_filsys fs, void *priv_data) {struct fill_dir_struct *fd = (struct fill_dir_struct *) priv_data; -struct hash_entry *new_array, *ent; +struct hash_entry *ent;struct ext2_dir_entry *dirent;char *dir;unsigned int offset, dir_offset, rec_len, name_len;
Signature · 1 line
2.21.3
PATCH 2/4 e2fsck: use size_t instead of int in string_copy()
len argument in string_copy() is int, but it is used with malloc(), strlen(), strncpy() and some callers use sizeof() to pass value in. So it really ought to be size_t rather than int. Fix it.
--- e2fsck/e2fsck.h | 2 +- e2fsck/util.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
e2fsck/e2fsck.h +1 -1
@@ -627,7 +627,7 @@ extern void log_err(e2fsck_t ctx, const char *fmt, ...)extern void e2fsck_read_bitmaps (e2fsck_t ctx);extern void e2fsck_write_bitmaps (e2fsck_t ctx);extern void preenhalt (e2fsck_t ctx); -extern char *string_copy (e2fsck_t ctx,const char *str,int len); +extern char *string_copy (e2fsck_t ctx,const char *str,size_t len);extern int fs_proc_check (const char *fs_name);extern int check_for_modules (const char *fs_name);#ifdef RESOURCE_TRACK
e2fsck/util.c +1 -1
@@ -135,7 +135,7 @@ void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size, } char *string_copy(e2fsck_t ctx EXT2FS_ATTR((unused)), - const char *str, int len) + const char *str, size_t len) { char *ret;
Signature · 1 line
2.21.3
Re: [PATCH 2/4] e2fsck: use size_t instead of int in string_copy()
Quoted 6 lines · Lukas Czerner
len argument in
string_copy()is int, but it is used withmalloc(),strlen(),strncpy()and some callers usesizeof()to pass value in. So it really ought to besize_trather than int. Fix it.Signed-off-by Lukas Czerner <[email protected]>
Thanks, having good types makes it much easier to follow code logic.
There are still a bunch of places in e2fsprogs that are using "int" and "long" for various blocks, counters, etc. that could use more precise types. I did a bunch of cleanup when I reviewd all of the directory and allocation code for 64-bit issues. It still lingers elsewhere, but every fix improves the code a bit, if we keep an eye on other incoming changes.
Quoted 32 lines
---
e2fsck/e2fsck.h| 2 +-e2fsck/util.c| 2 +-2 files changed, 2 insertions(+), 2 deletions(-)e2fsck/e2fsck.h +1
-1@@ -627,7 +627,7 @@ extern void log_err(e2fsck_t ctx, const char *fmt, ...)extern void e2fsck_read_bitmaps (e2fsck_t ctx);extern void e2fsck_write_bitmaps (e2fsck_t ctx);extern void preenhalt (e2fsck_t ctx); -extern char *string_copy (e2fsck_t ctx,const char *str,int len); +extern char *string_copy (e2fsck_t ctx,const char *str,size_t len);extern int fs_proc_check (const char *fs_name);extern int check_for_modules (const char *fs_name);#ifdef RESOURCE_TRACK e2fsck/util.c +1
-2@@ -135,7 +135,7 @@ void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size, } char *string_copy(e2fsck_t ctx EXT2FS_ATTR((unused)), - const char *str, int len) + const char *str, size_t len) { char *ret; --
Quoted 2 lines
2.21.3
Cheers, Andreas
Theodore Y. Ts'o
AppliedRe: [PATCH 2/4] e2fsck: use size_t instead of int in string_copy()
In reply to Lukas CzernerQuoted 5 lines · Lukas Czerner
len argument in
string_copy()is int, but it is used withmalloc(),strlen(),strncpy()and some callers usesizeof()to pass value in. So it really ought to besize_trather than int. Fix it.Signed-off-by Lukas Czerner <[email protected]>
Thanks, applied.
- Ted
PATCH 3/4 e2fsck: use the right conversion specifier in e2fsck_allocate_memory()
In reply to Lukas Czerner--- e2fsck/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
e2fsck/util.c +2 -2
@@ -123,10 +123,10 @@ void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,char buf[256 ];#ifdef DEBUG_ALLOCATE_MEMORY -printf ("Allocating %u bytes for %s...\n" , size, description); +printf ("Allocating %lu bytes for %s...\n" , size, description);#endif if (ext2fs_get_memzero (size, &ret)) { -sprintf (buf,"Can't allocate %u bytes for %s\n" , +sprintf (buf,"Can't allocate %lu bytes for %s\n" , size, description);fatal_error (ctx, buf); }
Signature · 1 line
2.21.3
Re: [PATCH 3/4] e2fsck: use the right conversion specifier in e2fsck_allocate_memory()
Quoted 2 lines · Lukas Czerner
Signed-off-by Lukas Czerner <[email protected]>
Quoted 22 lines
---
e2fsck/util.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)e2fsck/util.c +2
-3@@ -123,10 +123,10 @@ void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,char buf[256 ];#ifdef DEBUG_ALLOCATE_MEMORY -printf ("Allocating %u bytes for %s...\n" , size, description); +printf ("Allocating %lu bytes for %s...\n" , size, description);#endif if (ext2fs_get_memzero (size, &ret)) { -sprintf (buf,"Can't allocate %u bytes for %s\n" , +sprintf (buf,"Can't allocate %lu bytes for %s\n" , size, description);fatal_error (ctx, buf); } --
Quoted 2 lines
2.21.3
Cheers, Andreas
Re: [PATCH 3/4] e2fsck: use the right conversion specifier in e2fsck_allocate_memory()
In reply to Lukas CzernerThanks, I had fixed this in one place, but the fix under the #ifdef DEBUG_ALLOCATE_MEMORY needed, so that part has been applied.
- Ted
Quoted 25 lines · Lukas Czerner
Signed-off-by Lukas Czerner <[email protected]>--- e2fsck/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)e2fsck/util.c +2
-2@@ -123,10 +123,10 @@ void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,char buf[256 ];#ifdef DEBUG_ALLOCATE_MEMORY -printf ("Allocating %u bytes for %s...\n" , size, description); +printf ("Allocating %lu bytes for %s...\n" , size, description);#endif if (ext2fs_get_memzero (size, &ret)) { -sprintf (buf,"Can't allocate %u bytes for %s\n" , +sprintf (buf,"Can't allocate %lu bytes for %s\n" , size, description);fatal_error (ctx, buf); }Signature · 1 line
2.21.3
PATCH 4/4 ext2fs: remove unused variable 'left'
In reply to Lukas Czerner--- lib/ext2fs/swapfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/ext2fs/swapfs.c +1 -2
@@ -456,12 +456,11 @@ errcode_t ext2fs_dirent_swab_out2(ext2_filsys fs, char *buf, {errcode_t retval;char *p, *end; -unsigned int rec_len, left; +unsigned int rec_len;struct ext2_dir_entry *dirent; p = buf; end = buf + size; - left = size;while (p < end) { dirent = (struct ext2_dir_entry *) p; retval =ext2fs_get_rec_len (fs, dirent, &rec_len);
Signature · 1 line
2.21.3
Re: [PATCH 4/4] ext2fs: remove unused variable 'left'
Quoted 2 lines · Lukas Czerner
Signed-off-by Lukas Czerner <[email protected]>
Quoted 23 lines
---
lib/ext2fs/swapfs.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)lib/ext2fs/swapfs.c +1
-3@@ -456,12 +456,11 @@ errcode_t ext2fs_dirent_swab_out2(ext2_filsys fs, char *buf, {errcode_t retval;char *p, *end; -unsigned int rec_len, left; +unsigned int rec_len;struct ext2_dir_entry *dirent; p = buf; end = buf + size; - left = size;while (p < end) { dirent = (struct ext2_dir_entry *) p; retval =ext2fs_get_rec_len (fs, dirent, &rec_len); --
Quoted 2 lines
2.21.3
Cheers, Andreas
Theodore Y. Ts'o
AppliedRe: [PATCH 4/4] ext2fs: remove unused variable 'left'
In reply to Lukas CzernerQuoted 4 lines · Lukas Czerner
Signed-off-by Lukas Czerner <[email protected]>
Quoted 18 lines
---
e2fsck/rehash.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)e2fsck/rehash.c +1
-2@@ -109,7 +109,7 @@ static int fill_dir_block(ext2_filsys fs, void *priv_data) {struct fill_dir_struct *fd = (struct fill_dir_struct *) priv_data; -struct hash_entry *new_array, *ent; +struct hash_entry *ent;struct ext2_dir_entry *dirent;char *dir;unsigned int offset, dir_offset, rec_len, name_len; --
Quoted 2 lines
2.21.3
Cheers, Andreas
Quoted 13 lines · Lukas Czerner
Signed-off-by Lukas Czerner <[email protected]>---
e2fsck/rehash.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)e2fsck/rehash.c +0
-0
e2fsck/rehash.c static int fill_dir_block(ext2_filsys fs, · line 112
Quoted 5 lines
e2fsck/rehash.c +1
-1@@ -109,7 +109,7 @@ static int fill_dir_block(ext2_filsys fs, void *priv_data) {struct fill_dir_struct *fd = (struct fill_dir_struct *) priv_data; -struct hash_entry *new_array, *ent; +struct hash_entry *ent;
PS - there is a space before the tab after "hash_entry" that could be removed. Ted could fix this when the patch is applied.
Cheers, Andreas
Quoted 21 lines · Lukas Czerner
Signed-off-by Lukas Czerner <[email protected]>--- e2fsck/rehash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)e2fsck/rehash.c +1
-1@@ -109,7 +109,7 @@ static int fill_dir_block(ext2_filsys fs, void *priv_data) {struct fill_dir_struct *fd = (struct fill_dir_struct *) priv_data; -struct hash_entry *new_array, *ent; +struct hash_entry *ent;struct ext2_dir_entry *dirent;char *dir;unsigned int offset, dir_offset, rec_len, name_len;Signature · 1 line
2.21.3
Ehm, ping ?
-Lukas
Thanks, this was fixed already.
- Ted