@@ -346,10 +346,10 @@ static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
346
346
strbuf_trim (subject );
347
347
}
348
348
349
- #define MAX_HDR_PARSED 10
350
- static const char * header [MAX_HDR_PARSED ] = {
351
- "From" ,"Subject" ,"Date" ,
349
+ static const char * const header [] = {
350
+ "From" , "Subject" , "Date" ,
352
351
};
352
+ #define MAX_HDR_PARSED (ARRAY_SIZE(header) + 1)
353
353
354
354
static inline int skip_header (const struct strbuf * line , const char * hdr ,
355
355
const char * * outval )
@@ -583,7 +583,7 @@ static int check_header(struct mailinfo *mi,
583
583
struct strbuf sb = STRBUF_INIT ;
584
584
585
585
/* search for the interesting parts */
586
- for (i = 0 ; header [ i ] ; i ++ ) {
586
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ ) {
587
587
if ((!hdr_data [i ] || overwrite ) &&
588
588
parse_header (line , header [i ], mi , & sb )) {
589
589
handle_header (& hdr_data [i ], & sb );
@@ -625,7 +625,7 @@ static int is_inbody_header(const struct mailinfo *mi,
625
625
{
626
626
int i ;
627
627
const char * val ;
628
- for (i = 0 ; header [ i ] ; i ++ )
628
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ )
629
629
if (!mi -> s_hdr_data [i ] && skip_header (line , header [i ], & val ))
630
630
return 1 ;
631
631
return 0 ;
@@ -772,7 +772,7 @@ static int check_inbody_header(struct mailinfo *mi, const struct strbuf *line)
772
772
return is_format_patch_separator (line -> buf + 1 , line -> len - 1 );
773
773
if (starts_with (line -> buf , "[PATCH]" ) && isspace (line -> buf [7 ])) {
774
774
int i ;
775
- for (i = 0 ; header [ i ] ; i ++ )
775
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ )
776
776
if (!strcmp ("Subject" , header [i ])) {
777
777
handle_header (& mi -> s_hdr_data [i ], line );
778
778
return 1 ;
@@ -824,7 +824,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
824
824
* We may have already read "secondary headers"; purge
825
825
* them to give ourselves a clean restart.
826
826
*/
827
- for (i = 0 ; header [ i ] ; i ++ ) {
827
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ ) {
828
828
if (mi -> s_hdr_data [i ])
829
829
strbuf_release (mi -> s_hdr_data [i ]);
830
830
FREE_AND_NULL (mi -> s_hdr_data [i ]);
@@ -1155,7 +1155,7 @@ static void handle_info(struct mailinfo *mi)
1155
1155
struct strbuf * hdr ;
1156
1156
int i ;
1157
1157
1158
- for (i = 0 ; header [ i ] ; i ++ ) {
1158
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ ) {
1159
1159
/* only print inbody headers if we output a patch file */
1160
1160
if (mi -> patch_lines && mi -> s_hdr_data [i ])
1161
1161
hdr = mi -> s_hdr_data [i ];
0 commit comments