public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Yang Guang <cgel.zte@gmail.com>
Cc: Yang Guang <yang.guang5@zte.com.cn>,
	Zeal Robot <zealci@zte.com.cn>,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] gcc-plugins: use swap() to make code cleaner
Date: Thu, 2 Dec 2021 11:35:59 -0800	[thread overview]
Message-ID: <202112021134.7ECC69C1@keescook> (raw)
In-Reply-To: <20211028003526.7117-1-yang.guang5@zte.com.cn>

On Thu, Oct 28, 2021 at 12:35:26AM +0000, Yang Guang wrote:
> Using swap() make it more readable.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
> ---
>  scripts/gcc-plugins/randomize_layout_plugin.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c
> index 334741a31d0a..feee5ba8fa2b 100644
> --- a/scripts/gcc-plugins/randomize_layout_plugin.c
> +++ b/scripts/gcc-plugins/randomize_layout_plugin.c
> @@ -244,11 +244,8 @@ static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state
>  	unsigned long i, randnum;
>  
>  	for (i = length - 1; i > 0; i--) {
> -		tree tmp;
>  		randnum = ranval(prng_state) % (i + 1);
> -		tmp = newtree[i];
> -		newtree[i] = newtree[randnum];
> -		newtree[randnum] = tmp;
> +		swap(newtree[i], newtree[randnum]);
>  	}
>  }

Hmm, I don't think you compile-tested this? The gcc plugins are build in
userspace without the kernel headers (i.e. no "swap" macro). I'd be
happy to avoid open-coding this, but that would require a new macro
specific to the gcc plugins (to avoid std::swap). Also, there are two
other open-coded swaps in here that could be changed too. :)

-Kees

-- 
Kees Cook

      reply	other threads:[~2021-12-02 19:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28  0:35 [PATCH] gcc-plugins: use swap() to make code cleaner Yang Guang
2021-12-02 19:35 ` Kees Cook [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202112021134.7ECC69C1@keescook \
    --to=keescook@chromium.org \
    --cc=cgel.zte@gmail.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yang.guang5@zte.com.cn \
    --cc=zealci@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox