Re: A couple of gripes about the gettext plurals patch - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: A couple of gripes about the gettext plurals patch
Date
Msg-id 200905261345.00783.peter_e@gmx.net
Whole thread Raw
In response to Re: A couple of gripes about the gettext plurals patch  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: A couple of gripes about the gettext plurals patch  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Monday 25 May 2009 22:02:47 Tom Lane wrote:
> The issue of double translation is really a minor point; what is
> bothering me is that we've got such an ad-hoc,
> non-compile-time-checkable approach here.  Zdenek's discovery
> today that some of the format strings are flat-out wrong
> http://archives.postgresql.org/pgsql-hackers/2009-05/msg00946.php
> surprises me not in the least.

See response there why this is the way it is.

Note also that gcc's format argument checking can see through ngettext() quite 
well, so as far as I can tell, we are not exposed to accidental format string 
mismatches.

Example code:

#include <stdarg.h>
#include <stdio.h>
#include <libintl.h>

extern void errmsg(const char *fmt, ...) __attribute__((format(printf,1,2)));

void
errmsg(const char *fmt, ...)
{       va_list ap;
       va_start(ap, fmt);       vfprintf(stderr, fmt, ap);       va_end(ap);
}


int
main(int argc, char *argv[])
{       errmsg(ngettext("got %d argument, namely %s\n",                       "got %d arguments, first ist %s\n",
argc),                      argc, argv[0]);       return 0;
 
}

I tried throwing various kinds of subtle garbage into the errmsg/ngettext 
line, but it was all discovered by gcc -Wall.



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: problem with plural-forms
Next
From: Andres Freund
Date:
Subject: Re: [PATCH] cleanup hashindex for pg_migrator hashindex compat mode (for 8.4)