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: <cefe24b6-c1a1-4fe4-826d-e08a856aa8e0@p183>
Date: Mon, 12 May 2025 19:20:23 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: David Laight <david.laight.linux@...il.com>
Cc: corbet@....net, workflows@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 8/9] CodingStyle: tell people how to split long "for"
 loops

On Sat, May 10, 2025 at 07:56:03PM +0100, David Laight wrote:
> On Fri,  9 May 2025 23:34:29 +0300
> Alexey Dobriyan <adobriyan@...il.com> wrote:
> 
> > Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
> > ---
> >  Documentation/process/coding-style.rst | 16 +++++++++++++++-
> >  1 file changed, 15 insertions(+), 1 deletion(-)
> > 
> > diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst
> > index e17de69845ff..494ab3201112 100644
> > --- a/Documentation/process/coding-style.rst
> > +++ b/Documentation/process/coding-style.rst
> > @@ -183,7 +183,21 @@ Descendants are always substantially shorter than the parent and
> >  are placed substantially to the right.  A very commonly used style
> >  is to align descendants to a function open parenthesis.
> >  
> > -These same rules are applied to function headers with a long argument list.
> > +These same rules are applied to function prototypes with a long argument list.
> > +
> > +Very long ``for`` loops are split at the ``;`` characters making it easier
> > +to see which code goes to which clause:
> > +
> > +.. code-block:: c
> > +
> > +	for (int i = 0;
> > +	     i < N;
> > +	     i += 1)
> > +	{
> > +	}
> > +
> > +Opening curly is placed on a separate line then to make it easier to tell
> > +loop body from iteration clause.
> 
> Is that actually the style - I don't remember seeing it.

Check include/linux/list.h.

The point here is that it is either 1 line or 3 (not 2).
If you start splitting for loop there are 2 obvious points to do so.

> The location of the { isn't a significant problem with for (;;), it can be
> much worse elsewhere.
> In reality the 'align with the (' is what causes the problems, either
> double indenting (two tabs) or half indent (4 spaces - to annoy anyone who
> sets an editor to 4 space tabs) is more readable.
> 
> For for (;;) loops I'll normally try moving the initialisation outside the
> loop

That's slightly bad -- variables could leak outside.

> and even put an inverted condition inside the loop to avoid long lines.

> If a #define all bets are off :-)

It applies even more inside #define: #define shits everything by 1 indent usually
so more chance of split line,
it is harder tom see semicolons because macro body is usually colored in
1 color not the normal way.

Do you like how xas_for_each() look like?
"for" macros in include/linux/list.h look mostly OK.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ