Skip to contentSkip to conversation

e2fsck: remove unused variable 'new_array'

PATCH Applied Lukas Czerner 3 participants 14 messages Jun 5, 2020 – Oct 1, 2020

lore
Share & tools
lore
#0 lore raw

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
index 1616d07a..b356b92d 100644
@@ -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
#1 lore raw

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
index 9b2b9ce8..85f953b2 100644
@@ -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
index d98b8e47..88e0ea8a 100644
@@ -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
Reviewed-by on v1 2/4
#2 lore raw

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 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.

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
index 9b2b9ce8..85f953b2 100644
@@ -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
index d98b8e47..88e0ea8a 100644
@@ -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

#3 lore raw

Re: [PATCH 2/4] e2fsck: use size_t instead of int in string_copy()

In reply to Lukas Czerner
Quoted 5 lines · Lukas Czerner

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.

Thanks, applied.

- Ted

#4 lore raw

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
index 88e0ea8a..79916928 100644
@@ -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
Reviewed-by on v1 3/4
#5 lore raw

Re: [PATCH 3/4] e2fsck: use the right conversion specifier in e2fsck_allocate_memory()

Quoted 2 lines · Lukas Czerner
Quoted 22 lines

---
e2fsck/util.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
e2fsck/util.c +2 -3
index 88e0ea8a..79916928 100644
@@ -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

#6 lore raw

Re: [PATCH 3/4] e2fsck: use the right conversion specifier in e2fsck_allocate_memory()

In reply to Lukas Czerner

Thanks, 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
---
 e2fsck/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
e2fsck/util.c +2 -2
index 88e0ea8a..79916928 100644
@@ -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
#7 lore raw

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
index 5b93b501..bc9f3230 100644
@@ -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
Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] ext2fs: remove unused variable 'left'

Quoted 2 lines · Lukas Czerner
Quoted 23 lines

---
lib/ext2fs/swapfs.c | 3 +--

1 file changed, 1 insertion(+), 2 deletions(-)
lib/ext2fs/swapfs.c +1 -3
index 5b93b501..bc9f3230 100644
@@ -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

Reviewed-by on v1 1/4
#10 lore raw
In reply to Lukas Czerner
Quoted 4 lines · Lukas Czerner
Quoted 18 lines

---
e2fsck/rehash.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
e2fsck/rehash.c +1 -2
index 1616d07a..b356b92d 100644
@@ -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

#11 lore raw
In reply to Lukas Czerner
Quoted 13 lines · Lukas Czerner

---
e2fsck/rehash.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
e2fsck/rehash.c +0 -0
index 1616d07a..b356b92d 100644

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

#12 lore raw
In reply to Lukas Czerner
Quoted 21 lines · Lukas Czerner
---
 e2fsck/rehash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
e2fsck/rehash.c +1 -1
index 1616d07a..b356b92d 100644
@@ -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