Re: reading uninitialized buffer

From: Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: reading uninitialized buffer
Date: 2004-02-01 15:12:17
Message-ID: Pine.LNX.4.44.0402011557240.30205-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2004-02-01 16:13:38 Re: reading uninitialized buffer
Previous Message Andrew Dunstan 2004-02-01 14:20:28 Re: reading uninitialized buffer