Skip to content

Commit

Permalink
Merge pull request #67 from boeglin/fix_usage_segfault
Browse files Browse the repository at this point in the history
Prevent segfault when argparse_usage() is called twice
  • Loading branch information
cofyc-bot authored Jul 3, 2024
2 parents c612dc0 + ea306fc commit ccb8d24
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions argparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ void
argparse_usage(struct argparse *self)
{
if (self->usages) {
fprintf(stdout, "Usage: %s\n", *self->usages++);
while (*self->usages && **self->usages)
fprintf(stdout, " or: %s\n", *self->usages++);
const char *const *usages = self->usages;
fprintf(stdout, "Usage: %s\n", *usages++);
while (*usages && **usages)
fprintf(stdout, " or: %s\n", *usages++);
} else {
fprintf(stdout, "Usage:\n");
}
Expand Down

0 comments on commit ccb8d24

Please sign in to comment.