]> Savannah Git Hosting - gnulib.git/commitdiff
argp: Don't pass an invalid argument to dgettext().
authorBruno Haible <bruno@clisp.org>
Sat, 5 Jan 2019 16:00:53 +0000 (17:00 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 5 Jan 2019 16:00:53 +0000 (17:00 +0100)
Reported by He X <xw897002528@gmail.com>.

* lib/argp.h (struct argp): Clarify that the args_doc field may be NULL.
* lib/argp-help.c (argp_args_usage): Don't pass a NULL args_doc to
dgettext().

ChangeLog
lib/argp-help.c
lib/argp.h

index bb3598a414baa9246a63d8b7cc113d10f47b2919..2709cb173db6da7818a309794ab740db921bf096 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-01-05  Bruno Haible  <bruno@clisp.org>
+
+       argp: Don't pass an invalid argument to dgettext().
+       Reported by He X <xw897002528@gmail.com>.
+       * lib/argp.h (struct argp): Clarify that the args_doc field may be NULL.
+       * lib/argp-help.c (argp_args_usage): Don't pass a NULL args_doc to
+       dgettext().
+
 2018-12-22  Paul Eggert  <eggert@cs.ucla.edu>
 
        stdioext: port to newer 32-bit Android
index e5375a0f044d7257061a3977ab8f336211ce7cec..e5e97ecf6cefe0b0ef0525611c7c02f9a1aa3ab1 100644 (file)
@@ -1412,8 +1412,10 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state,
   char *our_level = *levels;
   int multiple = 0;
   const struct argp_child *child = argp->children;
-  const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0;
+  const char *tdoc =
+    argp->args_doc ? dgettext (argp->argp_domain, argp->args_doc) : NULL;
   const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
+  const char *nl = NULL;
 
   if (fdoc)
     {
index 317ac034e01f93ba37f3ac7c785027dd6ebfbc05..7aba8877dd15df3603ff7f82267a81395b1af7e6 100644 (file)
@@ -69,6 +69,9 @@ typedef int error_t;
 extern "C" {
 #endif
 
+/* Glibc documentation:
+   https://www.gnu.org/software/libc/manual/html_node/Argp.html */
+
 /* A description of a particular option.  A pointer to an array of
    these is passed in the OPTIONS field of an argp structure.  Each option
    entry can correspond to one long option and/or one short option; more
@@ -236,9 +239,9 @@ struct argp
      ARGP_KEY_ definitions below.  */
   argp_parser_t parser;
 
-  /* A string describing what other arguments are wanted by this program.  It
-     is only used by argp_usage to print the "Usage:" message.  If it
-     contains newlines, the strings separated by them are considered
+  /* If non-NULL, a string describing what other arguments are wanted by this
+     program.  It is only used by argp_usage to print the "Usage:" message.
+     If it contains newlines, the strings separated by them are considered
      alternative usage patterns, and printed on separate lines (lines after
      the first are prefix by "  or: " instead of "Usage:").  */
   const char *args_doc;