Skip to content

Commit ff3fe55

Browse files
committed
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().
1 parent d91fe44 commit ff3fe55

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2019-01-05 Bruno Haible <bruno@clisp.org>
2+
3+
argp: Don't pass an invalid argument to dgettext().
4+
Reported by He X <xw897002528@gmail.com>.
5+
* lib/argp.h (struct argp): Clarify that the args_doc field may be NULL.
6+
* lib/argp-help.c (argp_args_usage): Don't pass a NULL args_doc to
7+
dgettext().
8+
19
2018-12-22 Paul Eggert <eggert@cs.ucla.edu>
210

311
stdioext: port to newer 32-bit Android

lib/argp-help.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,10 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state,
14121412
char *our_level = *levels;
14131413
int multiple = 0;
14141414
const struct argp_child *child = argp->children;
1415-
const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0;
1415+
const char *tdoc =
1416+
argp->args_doc ? dgettext (argp->argp_domain, argp->args_doc) : NULL;
14161417
const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
1418+
const char *nl = NULL;
14171419

14181420
if (fdoc)
14191421
{

lib/argp.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ typedef int error_t;
6969
extern "C" {
7070
#endif
7171

72+
/* Glibc documentation:
73+
https://www.gnu.org/software/libc/manual/html_node/Argp.html */
74+
7275
/* A description of a particular option. A pointer to an array of
7376
these is passed in the OPTIONS field of an argp structure. Each option
7477
entry can correspond to one long option and/or one short option; more
@@ -236,9 +239,9 @@ struct argp
236239
ARGP_KEY_ definitions below. */
237240
argp_parser_t parser;
238241

239-
/* A string describing what other arguments are wanted by this program. It
240-
is only used by argp_usage to print the "Usage:" message. If it
241-
contains newlines, the strings separated by them are considered
242+
/* If non-NULL, a string describing what other arguments are wanted by this
243+
program. It is only used by argp_usage to print the "Usage:" message.
244+
If it contains newlines, the strings separated by them are considered
242245
alternative usage patterns, and printed on separate lines (lines after
243246
the first are prefix by " or: " instead of "Usage:"). */
244247
const char *args_doc;

0 commit comments

Comments
 (0)