Re: pg_avd - Mailing list pgsql-patches

From Tom Lane
Subject Re: pg_avd
Date
Msg-id 23463.1045580856@sss.pgh.pa.us
Whole thread Raw
In response to Re: pg_avd  (Neil Conway <neilc@samurai.com>)
Responses Re: pg_avd
List pgsql-patches
Neil Conway <neilc@samurai.com> writes:
> Some minor nit-picking follows below. I tend to be a bit of a
> style-nazi, don't mind me :-)

> - the length argument to snprintf() includes the terminating NUL byte,
> so code like pg_avd.c line 334 is off-by-one:

>   char buf[256];
>   /* ... */
>   snprintf(buf,255,"...");

Actually the preferred coding of this is

    snprintf(buf, sizeof(buf), ...);

which is both correct and impervious to subsequent alteration of the
declared size of buf.  I get antsy whenever I see a snprintf with a
literal-constant size argument, because it's a mistake waiting to
happen.  Use sizeof() when you can, or at least a #define.

            regards, tom lane

pgsql-patches by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: Re: Non-colliding auto generated names
Next
From: Tom Lane
Date:
Subject: Re: Non-colliding auto generated names