Re: What behavior is in this loop? - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: What behavior is in this loop?
Date
Msg-id 530F1F5A.8090907@vmware.com
Whole thread Raw
In response to What behavior is in this loop?  (KONDO Mitsumasa <kondo.mitsumasa@lab.ntt.co.jp>)
Responses Re: What behavior is in this loop?  (KONDO Mitsumasa <kondo.mitsumasa@lab.ntt.co.jp>)
List pgsql-hackers
On 02/27/2014 12:38 PM, KONDO Mitsumasa wrote:
> I found interesting "for" and "while" loop in WaitForWALToBecomeAvailable() in
> xlog.c. Can you tell me this behavior?
>
> for (;;)
> {
> ~
> } while (StanbyMode)
>
> I confirmed this code is no problem in gcc compiler:)

Oh wow :-). That's clearly a thinko, although harmless in this case. 
Looking at the git history, I made that mistake in commit abf5c5c9a. 
Before that, there was no "while".

That's easier to understand with some extra formatting. That's two 
loops, like this:

/* loop 1 */
for (;;)
{  ...
}

/* loop2 */
while(StandbyMode);

The second loop is obviously completely pointless. Thankfully, the there 
are no "breaks" inside the first loop (the ones within the 
switch-statements don't count), so the endless while-loop is never reached.

I'll go fix that... Thanks for the report!

- Heikki



pgsql-hackers by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: jsonb and nested hstore
Next
From: Robert Haas
Date:
Subject: Re: jsonb and nested hstore