From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Neil Conway <neilc(at)samurai(dot)com> |
Cc: | PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: minor smgr code cleanup |
Date: | 2004-01-06 00:18:47 |
Message-ID: | 29199.1073348327@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
Neil Conway <neilc(at)samurai(dot)com> writes:
> bool
> IsReservedName(const char *name)
> {
> ! /* ugly coding for speed */
> ! return (name[0] == 'p' &&
> ! name[1] == 'g' &&
> ! name[2] == '_');
> }
> --- 160,178 ----
> bool
> IsReservedName(const char *name)
> {
> ! return strncmp(name, "pg_", 3);
> }
This change is actually wrong (backwards), no? You want a true result
on equality.
In any case I don't think this is a step forward in readability, and it
also poses a portability risk. You should always write such tests as
return strncmp(name, "pg_", 3) == 0;
(or != 0 as appropriate). Pretending that the result of strcmp is a
bool is a type pun, and one that can rise up to bite you. In the case
at hand, strncmp is allowed to return (say) 256 to indicate a nonzero
result --- which would be lost when the value is squeezed into a bool
(char). See the archives; we've had at least one bug of this ilk.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2004-01-06 00:22:14 | List rewrite (was Re: minor smgr code cleanup) |
Previous Message | Kurt Roeckx | 2004-01-05 22:18:50 | Re: remove obsolete NULL casts |