@@ -669,22 +669,21 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
669669}
670670
671671static char *
672- longopts_to_optstring (const struct option opts [])
672+ longopts_to_optstring (const struct option opts [], const size_t len )
673673{
674- size_t len ;
675- char * result ;
676- char * s ;
674+ size_t i ;
675+ char * result ;
676+ char * s ;
677677
678- for (len = 0 ; opts [len ].name ; len ++ ) { }
679678 result = pgut_malloc (len * 2 + 1 );
680679
681680 s = result ;
682- for (len = 0 ; opts [ len ]. name ; len ++ )
681+ for (i = 0 ; i < len ; i ++ )
683682 {
684- if (!isprint (opts [len ].val ))
683+ if (!isprint (opts [i ].val ))
685684 continue ;
686- * s ++ = opts [len ].val ;
687- if (opts [len ].has_arg != no_argument )
685+ * s ++ = opts [i ].val ;
686+ if (opts [i ].has_arg != no_argument )
688687 * s ++ = ':' ;
689688 }
690689 * s = '\0' ;
@@ -731,18 +730,18 @@ pgut_getopt_env(pgut_option options[])
731730int
732731pgut_getopt (int argc , char * * argv , pgut_option options [])
733732{
734- int c ;
735- int optindex = 0 ;
736- char * optstring ;
737- pgut_option * opt ;
733+ int c ;
734+ int optindex = 0 ;
735+ char * optstring ;
736+ pgut_option * opt ;
738737 struct option * longopts ;
739- size_t len1 ;
738+ size_t len ;
740739
741- len1 = option_length (options );
742- longopts = pgut_newarray (struct option , len1 + 1 );
743- option_copy (longopts , options , len1 );
740+ len = option_length (options );
741+ longopts = pgut_newarray (struct option , len + 1 );
742+ option_copy (longopts , options , len );
744743
745- optstring = longopts_to_optstring (longopts );
744+ optstring = longopts_to_optstring (longopts , len );
746745
747746 /* Assign named options */
748747 while ((c = getopt_long (argc , argv , optstring , longopts , & optindex )) != -1 )
0 commit comments