# HG changeset patch # User Eric Blake # Date 1245953615 21600 # Node ID ed090c498dd0eefb4b1aa03ebb30fa8c17fa8cfd # Parent 22347e3d6b9590d534f44563f70dc9f9a76e2387 version-etc: fix regression * lib/version-etc.h (ATTRIBUTE_SENTINEL): Define for new enough gcc. (version_etc): Use it, to catch bugs with trailing NULL. * lib/version-etc.c (version_etc_arn): Delete unused argument. (version_etc_va): Fix logic bug. * modules/version-etc-tests: Add test. * tests/test-version-etc.c: New file. * tests/test-version-etc.sh: Likewise. Signed-off-by: Eric Blake diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-06-25 Eric Blake + + version-etc: fix regression + * lib/version-etc.h (ATTRIBUTE_SENTINEL): Define for new enough + gcc. + (version_etc): Use it, to catch bugs with trailing NULL. + * lib/version-etc.c (version_etc_arn): Delete unused argument. + (version_etc_va): Fix logic bug. + * modules/version-etc-tests: Add test. + * tests/test-version-etc.c: New file. + * tests/test-version-etc.sh: Likewise. + 2009-06-25 Sam Steingold * mbrtowc.m4 (gl_MBRTOWC_SANITYCHECK): Include , for the diff --git a/lib/version-etc.c b/lib/version-etc.c --- a/lib/version-etc.c +++ b/lib/version-etc.c @@ -161,7 +161,7 @@ fprintf (stream, _("\ Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"), authors[0], authors[1], authors[2], authors[3], authors[4], - authors[5], authors[6], authors[7], authors[8], authors[9]); + authors[5], authors[6], authors[7], authors[8]); break; } } @@ -196,7 +196,7 @@ for (n_authors = 0; n_authors < 10 - && (authtab[n_authors++] = va_arg (authors, const char *)) != NULL; + && (authtab[n_authors] = va_arg (authors, const char *)) != NULL; n_authors++) ; version_etc_arn (stream, command_name, package, version, diff --git a/lib/version-etc.h b/lib/version-etc.h --- a/lib/version-etc.h +++ b/lib/version-etc.h @@ -22,6 +22,15 @@ # include # include +/* The `sentinel' attribute was added in gcc 4.0. */ +#ifndef ATTRIBUTE_SENTINEL +# if 4 <= __GNUC__ +# define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__)) +# else +# define ATTRIBUTE_SENTINEL /* empty */ +# endif +#endif + extern const char version_etc_copyright[]; /* The three functions below display the --version information in the @@ -39,28 +48,29 @@ The functions differ in the way they are passed author names: */ -/* N_AUTHORS names are supplied in array AUTHORS */ +/* N_AUTHORS names are supplied in array AUTHORS. */ extern void version_etc_arn (FILE *stream, const char *command_name, const char *package, const char *version, const char * const * authors, size_t n_authors); -/* Names are passed in the NULL-terminated array AUTHORS */ +/* Names are passed in the NULL-terminated array AUTHORS. */ extern void version_etc_ar (FILE *stream, const char *command_name, const char *package, const char *version, const char * const * authors); -/* Names are passed in the NULL-terminated va_list */ +/* Names are passed in the NULL-terminated va_list. */ extern void version_etc_va (FILE *stream, const char *command_name, const char *package, const char *version, va_list authors); /* Names are passed as separate arguments, with an additional - NULL argument at the end. */ + NULL argument at the end. */ extern void version_etc (FILE *stream, const char *command_name, const char *package, const char *version, - /* const char *author1, ...*/ ...); + /* const char *author1, ..., NULL */ ...) + ATTRIBUTE_SENTINEL; /* Display the usual `Report bugs to' stanza */ extern void emit_bug_reporting_address (void); diff --git a/modules/version-etc-tests b/modules/version-etc-tests new file mode 100644 --- /dev/null +++ b/modules/version-etc-tests @@ -0,0 +1,13 @@ +Files: +tests/test-version-etc.c +tests/test-version-etc.sh + +Depends-on: +progname +version-etc-fsf + +Makefile.am: +TESTS += test-version-etc.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' +check_PROGRAMS += test-version-etc +test_version_etc_LDADD = $(LDADD) @LIBINTL@ diff --git a/tests/test-version-etc.c b/tests/test-version-etc.c new file mode 100644 --- /dev/null +++ b/tests/test-version-etc.c @@ -0,0 +1,33 @@ +/* Test suite for version-etc. + Copyright (C) 2009 Free Software Foundation, Inc. + This file is part of the GNUlib Library. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include "version-etc.h" + +#include "progname.h" + +#define AUTHORS "Sergey Poznyakoff", "Eric Blake" + +int +main (int argc, char **argv) +{ + set_program_name (argv[0]); + version_etc (stdout, "test-version-etc", "dummy", "0", AUTHORS, + (const char *) NULL); + return 0; +} diff --git a/tests/test-version-etc.sh b/tests/test-version-etc.sh new file mode 100755 --- /dev/null +++ b/tests/test-version-etc.sh @@ -0,0 +1,40 @@ +#! /bin/sh +# Test suite for version-etc. +# Copyright (C) 2009 Free Software Foundation, Inc. +# This file is part of the GNUlib Library. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +TMP=ve-expected.tmp +LC_ALL=C +export LC_ALL +ERR=0 + +cat > $TMP <. +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. + +Written by Sergey Poznyakoff and Eric Blake. +EOT + +./test-version-etc --version | + sed '2s/Copyright (C) [0-9]\{4,4\}/COPYRIGHT/' | + diff -c $TMP - || ERR=1 + +rm $TMP + +exit $ERR