diff mbox series

libext2fs: avoid pointer arithmetic on `void *`

Message ID 20200405045346.21860-1-mforney@mforney.org
State Accepted
Headers show
Series libext2fs: avoid pointer arithmetic on `void *` | expand

Commit Message

Michael Forney April 5, 2020, 4:53 a.m. UTC
The pointer operand to the binary `+` operator must be to a complete
object type.

Signed-off-by: Michael Forney <mforney@mforney.org>
---
 lib/ext2fs/csum.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Dilger April 6, 2020, 12:43 a.m. UTC | #1
On Apr 4, 2020, at 10:53 PM, Michael Forney <mforney@mforney.org> wrote:
> 
> The pointer operand to the binary `+` operator must be to a complete
> object type.
> 
> Signed-off-by: Michael Forney <mforney@mforney.org>

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

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> lib/ext2fs/csum.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/ext2fs/csum.c b/lib/ext2fs/csum.c
> index 8513d1ab..c2550365 100644
> --- a/lib/ext2fs/csum.c
> +++ b/lib/ext2fs/csum.c
> @@ -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;
> --
> 2.26.0
> 


Cheers, Andreas
Theodore Ts'o April 14, 2020, 1:59 a.m. UTC | #2
On Sun, Apr 05, 2020 at 06:43:09PM -0600, Andreas Dilger wrote:
> On Apr 4, 2020, at 10:53 PM, Michael Forney <mforney@mforney.org> wrote:
> > 
> > The pointer operand to the binary `+` operator must be to a complete
> > object type.
> > 
> > Signed-off-by: Michael Forney <mforney@mforney.org>
> 
> Seems straight forward enough.  Not needed for GCC, but strictly correct.
> 
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>

Applied, thanks.

					- Ted
diff mbox series

Patch

diff --git a/lib/ext2fs/csum.c b/lib/ext2fs/csum.c
index 8513d1ab..c2550365 100644
--- a/lib/ext2fs/csum.c
+++ b/lib/ext2fs/csum.c
@@ -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;