Re: reading uninitialized buffer - Mailing list pgsql-patches

From Dennis Bjorklund
Subject Re: reading uninitialized buffer
Date
Msg-id Pine.LNX.4.44.0402011557240.30205-100000@zigo.dhs.org
Whole thread Raw
In response to Re: reading uninitialized buffer  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: reading uninitialized buffer
List pgsql-patches
On Sun, 1 Feb 2004, Andrew Dunstan wrote:

> As for the test being outside the "if" statement, it is true that that
> might waste a few cycles, but it hardly matters.

The cycles are not important. My "fix" wasn't the most optimized either if
one should count cycles. It was terminating the string twice in some
cases. That I thought about and came to the conclusion that it was not
important.  That I didn't rewrite the strncmp() to strcmp() is strange to
me, the length is obviously not needed. Good thing you looked at it.

> Personally, I would prefer to replace the if statement with this:
>
>     if (c == EOF || c == '\n')
>     {
>         *buf = '\0';
>         return;
>     }
>
> and then it wouldn't be an issue at all, but I know some people don't
> like early function returns - is there a general postgres style rule

I don't know what the style rules say. I have nothing against early
returns if used with grace. Early exits for odd cases, before the main
part of the function, just helps readability if you ask me. On the other
hand it does not matter since the correct is always to use whatever style
the rest of the program uses.

--
/Dennis Björklund


pgsql-patches by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: reading uninitialized buffer
Next
From: Tom Lane
Date:
Subject: Re: reading uninitialized buffer