Skip site navigation (1) Skip section navigation (2)

Re: pg_avd

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: "Matthew T(dot) O'Connor" <matthew(at)zeut(dot)net>,PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: pg_avd
Date: 2003-02-18 15:07:36
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-patches
Neil Conway <neilc(at)samurai(dot)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

In response to

  • Re: pg_avd at 2003-02-18 08:24:29 from Neil Conway


  • Re: pg_avd at 2003-02-18 18:39:51 from Matthew T. O'Connor

pgsql-patches by date

Next:From: Tom LaneDate: 2003-02-18 15:57:56
Subject: Re: Non-colliding auto generated names
Previous:From: Christopher Kings-LynneDate: 2003-02-18 15:03:17
Subject: Re: Non-colliding auto generated names

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group