diff --git a/console/tidy.c b/console/tidy.c index 7f4659f..84a0cf5 100644 --- a/console/tidy.c +++ b/console/tidy.c @@ -693,6 +693,10 @@ void GetOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d ) ** Array holding all options. Contains a trailing sentinel. */ typedef struct { + /* Some options aren't exposed in the API although they're available + in the enum. This struct is guaranteed to hold *all* Tidy options, + but be sure to use the public API iterators to access them! + */ TidyOption topt[N_TIDY_OPTIONS]; } AllOption_t; @@ -723,8 +727,7 @@ static void getSortedOption( TidyDoc tdoc, AllOption_t *tOption ) tOption->topt[i] = NULL; /* sentinel */ qsort(tOption->topt, - /* Do not sort the sentinel: hence `-1' */ - sizeof(tOption->topt)/sizeof(tOption->topt[0])-1, + i, /* there are i items, not including the sentinal */ sizeof(tOption->topt[0]), cmpOpt); } diff --git a/src/config.c b/src/config.c index 8be57c0..014298b 100644 --- a/src/config.c +++ b/src/config.c @@ -1595,20 +1595,21 @@ TidyIterator TY_(getOptionList)( TidyDocImpl* ARG_UNUSED(doc) ) const TidyOptionImpl* TY_(getNextOption)( TidyDocImpl* ARG_UNUSED(doc), TidyIterator* iter ) { - const TidyOptionImpl* option = NULL; - size_t optId; - assert( iter != NULL ); - optId = (size_t) *iter; - if ( optId > TidyUnknownOption && optId < N_TIDY_OPTIONS ) - { - option = &option_defs[ optId ]; - optId++; - /* Hide these internal options from the API entirely. */ - if ( optId == TidyEmacsFile || optId == TidyDoctypeMode ) + const TidyOptionImpl* option = NULL; + size_t optId; + assert( iter != NULL ); + optId = (size_t) *iter; + if ( optId > TidyUnknownOption && optId < N_TIDY_OPTIONS ) + { + /* Hide these internal options from the API entirely. */ + while ( optId == TidyEmacsFile || optId == TidyDoctypeMode ) + optId++; + + option = &option_defs[ optId ]; optId++; - } - *iter = (TidyIterator) ( optId < N_TIDY_OPTIONS ? optId : (size_t)0 ); - return option; + } + *iter = (TidyIterator) ( optId < N_TIDY_OPTIONS ? optId : (size_t)0 ); + return option; } /* Use a 1-based array index as iterator: 0 == end-of-list