Skip to content

Commit

Permalink
optparse: avoid enum in optparse_get/set
Browse files Browse the repository at this point in the history
Change prototype of optparse_get() and optparse_set() to avoid
passing an enum as the argument to va_start() in these variadic
functions. Use of enum causes newer compiler to issue warnings of
the form:

 passing an object that undergoes default argument promotion
 to 'va_start' has undefined behavior [-Werror,-Wvarargs]

Change the enum argument in these functions to an integer to suppress
the warning and avoid potential undefined behavior.
  • Loading branch information
grondo committed Sep 8, 2017
1 parent 381cfc7 commit ec2011a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/common/liboptparse/optparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ optparse_err_t optparse_add_doc (optparse_t *p, const char *doc, int group)
return optparse_add_option (p, &o);
}

optparse_err_t optparse_set (optparse_t *p, optparse_item_t item, ...)
optparse_err_t optparse_set (optparse_t *p, int item, ...)
{
optparse_err_t e = OPTPARSE_SUCCESS;
va_list vargs;
Expand Down Expand Up @@ -1074,7 +1074,7 @@ static void * lookup_recursive (optparse_t *p, const char *key)
}


optparse_err_t optparse_get (optparse_t *p, optparse_item_t item, ...)
optparse_err_t optparse_get (optparse_t *p, int item, ...)
{
optparse_err_t e = OPTPARSE_SUCCESS;
va_list vargs;
Expand Down
4 changes: 2 additions & 2 deletions src/common/liboptparse/optparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ optparse_err_t optparse_add_option_table (optparse_t *p,
*/
optparse_err_t optparse_add_doc (optparse_t *p, const char *doc, int group);

optparse_err_t optparse_set (optparse_t *p, optparse_item_t item, ...);
optparse_err_t optparse_set (optparse_t *p, int item, ...);

optparse_err_t optparse_get (optparse_t *p, optparse_item_t item, ...);
optparse_err_t optparse_get (optparse_t *p, int item, ...);

/* Set and get arbitrary ancillary data associated with an optparse
* object. optparse_get_data () returns NULL if data not found.
Expand Down

0 comments on commit ec2011a

Please sign in to comment.