Re: pg_hba options parsing

Lists: pgsql-hackers
From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_hba options parsing
Date: 2008-10-20 07:28:28
Message-ID: 48FC331C.1050808@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> OK, a few comments:
>
> This should have spaces:
>
> ! port->hba->ldapprefix?port->hba->ldapprefix:"",

Fixed. Though I guess pgindent would've fixed it eventually otherwise.

> This is missing 'do' or something:
>
> + #define MANDATORY_AUTH_ARG(argvar, argname, authname) \
> + if (argvar == NULL) {\
> + ereport(LOG, \
> + (errcode(ERRCODE_CONFIG_FILE_ERROR), \
> + errmsg("authentication method '%s' requires argument '%s' to be set", \
> + authname, argname), \
> + errcontext("line %d of configuration file \"%s\"", \
> + line_num, HbaFileName))); \
> + goto hba_other_error; \
> + } while (0);

Wow.Amazing that it actually compiles and work. I guess it treats the
while(0) as a separate statement completely.

The correct fix is, AFAICS, to remove the while(0).

> Seems we are losing the sscanf(), which is good.

Yes, that is one of the goals :-)

If there are no further comments I will go ahead and commit this (with
the above fixes) within a couple of days.

//Magnus


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_hba options parsing
Date: 2008-10-20 12:51:24
Message-ID: 27421.1224507084@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander <magnus(at)hagander(dot)net> writes:
> Bruce Momjian wrote:
>> This is missing 'do' or something:
>>
>> + #define MANDATORY_AUTH_ARG(argvar, argname, authname) \
>> + if (argvar == NULL) {\
>> + ereport(LOG, \
>> + (errcode(ERRCODE_CONFIG_FILE_ERROR), \
>> + errmsg("authentication method '%s' requires argument '%s' to be set", \
>> + authname, argname), \
>> + errcontext("line %d of configuration file \"%s\"", \
>> + line_num, HbaFileName))); \
>> + goto hba_other_error; \
>> + } while (0);

> Wow.Amazing that it actually compiles and work. I guess it treats the
> while(0) as a separate statement completely.

> The correct fix is, AFAICS, to remove the while(0).

Absolutely not! The reason for using do/while in this sort of situation
is to make sure that the "if" can't get matched up to an "else" in code
following the macro. Without do/while this macro will be a loaded
foot-gun.

regards, tom lane


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_hba options parsing
Date: 2008-10-20 12:53:24
Message-ID: 48FC7F44.9070006@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Magnus Hagander <magnus(at)hagander(dot)net> writes:
>> Bruce Momjian wrote:
>>> This is missing 'do' or something:
>>>
>>> + #define MANDATORY_AUTH_ARG(argvar, argname, authname) \
>>> + if (argvar == NULL) {\
>>> + ereport(LOG, \
>>> + (errcode(ERRCODE_CONFIG_FILE_ERROR), \
>>> + errmsg("authentication method '%s' requires argument '%s' to be set", \
>>> + authname, argname), \
>>> + errcontext("line %d of configuration file \"%s\"", \
>>> + line_num, HbaFileName))); \
>>> + goto hba_other_error; \
>>> + } while (0);
>
>> Wow.Amazing that it actually compiles and work. I guess it treats the
>> while(0) as a separate statement completely.
>
>> The correct fix is, AFAICS, to remove the while(0).
>
> Absolutely not! The reason for using do/while in this sort of situation
> is to make sure that the "if" can't get matched up to an "else" in code
> following the macro. Without do/while this macro will be a loaded
> foot-gun.

Oh, didn't think of that. I just thought of the braces part, which was
"solved" by if. Thanks for clearing that up.

Ok, will add back do/while instead.

//Magnus