lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c6cf55b6-194c-47c8-a44-5266711cd3b@linux.intel.com>
Date:   Thu, 12 Jan 2023 10:58:08 +0200 (EET)
From:   Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To:     "Jiri Slaby (SUSE)" <jirislaby@...nel.org>
cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Kees Cook <keescook@...omium.org>,
        linux-serial <linux-serial@...r.kernel.org>,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 04/11] tty: vt: use sizeof(*variable) where possible

On Thu, 12 Jan 2023, Jiri Slaby (SUSE) wrote:

> Instead of sizeof(type), use sizeof(*variable) which is preferred. We
> are going to remove the unicode's char32_t typedef, so this makes the
> switch easier.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@...nel.org>
> ---
>  drivers/tty/vt/vt.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index 561c82e120cf..3ae0212f1aa7 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -330,11 +330,11 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
>  {
>  	struct uni_screen *uniscr;
>  	void *p;
> -	unsigned int memsize, i;
> +	unsigned int memsize, i, col_size = cols * sizeof(**uniscr->lines);
>  
>  	/* allocate everything in one go */
> -	memsize = cols * rows * sizeof(char32_t);
> -	memsize += rows * sizeof(char32_t *);
> +	memsize = col_size * rows;
> +	memsize += rows * sizeof(*uniscr->lines);

Wouldn't something from linux/overflow.h be more appropriate for these?

-- 
 i.

>  	p = vzalloc(memsize);
>  	if (!p)
>  		return NULL;
> @@ -344,7 +344,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
>  	p = uniscr->lines + rows;
>  	for (i = 0; i < rows; i++) {
>  		uniscr->lines[i] = p;
> -		p += cols * sizeof(char32_t);
> +		p += col_size;
>  	}
>  	return uniscr;
>  }
> @@ -469,7 +469,7 @@ static void vc_uniscr_copy_area(struct uni_screen *dst,
>  		char32_t *src_line = src->lines[src_top_row];
>  		char32_t *dst_line = dst->lines[dst_row];
>  
> -		memcpy(dst_line, src_line, src_cols * sizeof(char32_t));
> +		memcpy(dst_line, src_line, src_cols * sizeof(*src_line));
>  		if (dst_cols - src_cols)
>  			memset32(dst_line + src_cols, ' ', dst_cols - src_cols);
>  		src_top_row++;
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ