Skip to contentSkip to conversation

libext2fs: avoid pointer arithmetic on `void *`

PATCH Applied Michael Forney 3 participants 3 messages Apr 5, 2020 – Apr 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libext2fs: avoid pointer arithmetic on `void *`

The pointer operand to the binary + operator must be to a complete object type.

---
 lib/ext2fs/csum.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ext2fs/csum.c +1 -1
index 8513d1ab..c2550365 100644
@@ -274,7 +274,7 @@ static errcode_t __get_dirent_tail(ext2_filsys fs,
 		rec_len = translate(d->rec_len);
 	}
 
-	if ((void *)d > ((void *)dirent + fs->blocksize))
+	if ((char *)d > ((char *)dirent + fs->blocksize))
 			return EXT2_ET_DIR_CORRUPTED;
 	if (d != top)
 		return EXT2_ET_DIR_NO_SPACE_FOR_CSUM;
Signature · 1 line
2.26.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Michael Forney

The pointer operand to the binary + operator must be to a complete object type.

Seems straight forward enough. Not needed for GCC, but strictly correct.

Quoted 18 lines

---
lib/ext2fs/csum.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
lib/ext2fs/csum.c +1 -2
index 8513d1ab..c2550365 100644
@@ -274,7 +274,7 @@ static errcode_t __get_dirent_tail(ext2_filsys fs,
 		rec_len = translate(d->rec_len);
 	}
 
-	if ((void *)d > ((void *)dirent + fs->blocksize))
+	if ((char *)d > ((char *)dirent + fs->blocksize))
 			return EXT2_ET_DIR_CORRUPTED;
 	if (d != top)
 		return EXT2_ET_DIR_NO_SPACE_FOR_CSUM;
--
Quoted 2 lines

2.26.0

Cheers, Andreas