Mercurial > hg > octave-nkf > gnulib-hg
changeset 11655:ed090c498dd0
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 <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Thu, 25 Jun 2009 12:13:35 -0600 |
parents | 22347e3d6b95 |
children | 840c1aaa2f6d |
files | ChangeLog lib/version-etc.c lib/version-etc.h modules/version-etc-tests tests/test-version-etc.c tests/test-version-etc.sh |
diffstat | 6 files changed, 115 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-06-25 Eric Blake <ebb9@byu.net> + + 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 <sds@gnu.org> * mbrtowc.m4 (gl_MBRTOWC_SANITYCHECK): Include <stdlib.h>, for the
--- 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,
--- a/lib/version-etc.h +++ b/lib/version-etc.h @@ -22,6 +22,15 @@ # include <stdarg.h> # include <stdio.h> +/* 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);
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@
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 <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +#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; +}
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 <http://www.gnu.org/licenses/>. + +TMP=ve-expected.tmp +LC_ALL=C +export LC_ALL +ERR=0 + +cat > $TMP <<EOT +test-version-etc (dummy) 0 +COPYRIGHT Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. +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