@@ -669,22 +669,21 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg)
669
669
}
670
670
671
671
static char *
672
- longopts_to_optstring (const struct option opts [])
672
+ longopts_to_optstring (const struct option opts [], const size_t len )
673
673
{
674
- size_t len ;
675
- char * result ;
676
- char * s ;
674
+ size_t i ;
675
+ char * result ;
676
+ char * s ;
677
677
678
- for (len = 0 ; opts [len ].name ; len ++ ) { }
679
678
result = pgut_malloc (len * 2 + 1 );
680
679
681
680
s = result ;
682
- for (len = 0 ; opts [ len ]. name ; len ++ )
681
+ for (i = 0 ; i < len ; i ++ )
683
682
{
684
- if (!isprint (opts [len ].val ))
683
+ if (!isprint (opts [i ].val ))
685
684
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 )
688
687
* s ++ = ':' ;
689
688
}
690
689
* s = '\0' ;
@@ -731,18 +730,18 @@ pgut_getopt_env(pgut_option options[])
731
730
int
732
731
pgut_getopt (int argc , char * * argv , pgut_option options [])
733
732
{
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 ;
738
737
struct option * longopts ;
739
- size_t len1 ;
738
+ size_t len ;
740
739
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 );
744
743
745
- optstring = longopts_to_optstring (longopts );
744
+ optstring = longopts_to_optstring (longopts , len );
746
745
747
746
/* Assign named options */
748
747
while ((c = getopt_long (argc , argv , optstring , longopts , & optindex )) != -1 )
0 commit comments