Re: pg_hba options parsing - Mailing list pgsql-hackers

From Tom Lane
Subject Re: pg_hba options parsing
Date
Msg-id 27421.1224507084@sss.pgh.pa.us
Whole thread Raw
In response to Re: pg_hba options parsing  (Magnus Hagander <magnus@hagander.net>)
Responses Re: pg_hba options parsing
List pgsql-hackers
Magnus Hagander <magnus@hagander.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


pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: SSL cleanups/hostname verification
Next
From: Simon Riggs
Date:
Subject: Block level concurrency during recovery