version-etc: fix regression
authorEric Blake <ebb9@byu.net>
Thu, 25 Jun 2009 18:13:35 +0000 (12:13 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 26 Jun 2009 03:09:03 +0000 (21:09 -0600)
* 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>
ChangeLog
lib/version-etc.c
lib/version-etc.h
modules/version-etc-tests [new file with mode: 0644]
tests/test-version-etc.c [new file with mode: 0644]
tests/test-version-etc.sh [new file with mode: 0755]

index 15adf51..3e5fdb1 100644 (file)
--- 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
index 9580f53..a580140 100644 (file)
@@ -161,7 +161,7 @@ Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
       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 @@ version_etc_va (FILE *stream,
 
   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,
index 078601c..8ce02fe 100644 (file)
 # 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 @@ extern const char version_etc_copyright[];
 
    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 (file)
index 0000000..94ff3b7
--- /dev/null
@@ -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 (file)
index 0000000..71cbc8b
--- /dev/null
@@ -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;
+}
diff --git a/tests/test-version-etc.sh b/tests/test-version-etc.sh
new file mode 100755 (executable)
index 0000000..3b2fc4d
--- /dev/null
@@ -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