@@ -348,9 +348,8 @@ static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
348
348
strbuf_trim (subject );
349
349
}
350
350
351
- #define MAX_HDR_PARSED 10
352
- static const char * header [MAX_HDR_PARSED ] = {
353
- "From" ,"Subject" ,"Date" ,
351
+ static const char * const header [] = {
352
+ "From" , "Subject" , "Date" ,
354
353
};
355
354
356
355
static inline int skip_header (const struct strbuf * line , const char * hdr ,
@@ -585,7 +584,7 @@ static int check_header(struct mailinfo *mi,
585
584
struct strbuf sb = STRBUF_INIT ;
586
585
587
586
/* search for the interesting parts */
588
- for (i = 0 ; header [ i ] ; i ++ ) {
587
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ ) {
589
588
if ((!hdr_data [i ] || overwrite ) &&
590
589
parse_header (line , header [i ], mi , & sb )) {
591
590
handle_header (& hdr_data [i ], & sb );
@@ -627,7 +626,7 @@ static int is_inbody_header(const struct mailinfo *mi,
627
626
{
628
627
int i ;
629
628
const char * val ;
630
- for (i = 0 ; header [ i ] ; i ++ )
629
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ )
631
630
if (!mi -> s_hdr_data [i ] && skip_header (line , header [i ], & val ))
632
631
return 1 ;
633
632
return 0 ;
@@ -774,7 +773,7 @@ static int check_inbody_header(struct mailinfo *mi, const struct strbuf *line)
774
773
return is_format_patch_separator (line -> buf + 1 , line -> len - 1 );
775
774
if (starts_with (line -> buf , "[PATCH]" ) && isspace (line -> buf [7 ])) {
776
775
int i ;
777
- for (i = 0 ; header [ i ] ; i ++ )
776
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ )
778
777
if (!strcmp ("Subject" , header [i ])) {
779
778
handle_header (& mi -> s_hdr_data [i ], line );
780
779
return 1 ;
@@ -826,7 +825,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
826
825
* We may have already read "secondary headers"; purge
827
826
* them to give ourselves a clean restart.
828
827
*/
829
- for (i = 0 ; header [ i ] ; i ++ ) {
828
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ ) {
830
829
if (mi -> s_hdr_data [i ])
831
830
strbuf_release (mi -> s_hdr_data [i ]);
832
831
FREE_AND_NULL (mi -> s_hdr_data [i ]);
@@ -1157,7 +1156,7 @@ static void handle_info(struct mailinfo *mi)
1157
1156
struct strbuf * hdr ;
1158
1157
int i ;
1159
1158
1160
- for (i = 0 ; header [ i ] ; i ++ ) {
1159
+ for (i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ ) {
1161
1160
/* only print inbody headers if we output a patch file */
1162
1161
if (mi -> patch_lines && mi -> s_hdr_data [i ])
1163
1162
hdr = mi -> s_hdr_data [i ];
@@ -1208,8 +1207,8 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
1208
1207
return -1 ;
1209
1208
}
1210
1209
1211
- mi -> p_hdr_data = xcalloc (MAX_HDR_PARSED , sizeof (* (mi -> p_hdr_data )));
1212
- mi -> s_hdr_data = xcalloc (MAX_HDR_PARSED , sizeof (* (mi -> s_hdr_data )));
1210
+ mi -> p_hdr_data = xcalloc (ARRAY_SIZE ( header ) , sizeof (* (mi -> p_hdr_data )));
1211
+ mi -> s_hdr_data = xcalloc (ARRAY_SIZE ( header ) , sizeof (* (mi -> s_hdr_data )));
1213
1212
1214
1213
do {
1215
1214
peek = fgetc (mi -> input );
@@ -1292,15 +1291,15 @@ void clear_mailinfo(struct mailinfo *mi)
1292
1291
strbuf_release (& mi -> inbody_header_accum );
1293
1292
free (mi -> message_id );
1294
1293
1295
- for (size_t i = 0 ; header [ i ] ; i ++ ) {
1294
+ for (size_t i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ ) {
1296
1295
if (!mi -> p_hdr_data [i ])
1297
1296
continue ;
1298
1297
strbuf_release (mi -> p_hdr_data [i ]);
1299
1298
free (mi -> p_hdr_data [i ]);
1300
1299
}
1301
1300
free (mi -> p_hdr_data );
1302
1301
1303
- for (size_t i = 0 ; header [ i ] ; i ++ ) {
1302
+ for (size_t i = 0 ; i < ARRAY_SIZE ( header ) ; i ++ ) {
1304
1303
if (!mi -> s_hdr_data [i ])
1305
1304
continue ;
1306
1305
strbuf_release (mi -> s_hdr_data [i ]);
0 commit comments