Skip to content

Commit be10ac7

Browse files
committed
mailinfo: we parse fixed headers
The code was written as if we have a small room to add additional headers to be parsed to the header[] array at runtime, but that is not our intention at all. Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa3b914 commit be10ac7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

mailinfo.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,10 @@ static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
346346
strbuf_trim(subject);
347347
}
348348

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",
352351
};
352+
#define MAX_HDR_PARSED (ARRAY_SIZE(header) + 1)
353353

354354
static inline int skip_header(const struct strbuf *line, const char *hdr,
355355
const char **outval)
@@ -583,7 +583,7 @@ static int check_header(struct mailinfo *mi,
583583
struct strbuf sb = STRBUF_INIT;
584584

585585
/* search for the interesting parts */
586-
for (i = 0; header[i]; i++) {
586+
for (i = 0; i < ARRAY_SIZE(header); i++) {
587587
if ((!hdr_data[i] || overwrite) &&
588588
parse_header(line, header[i], mi, &sb)) {
589589
handle_header(&hdr_data[i], &sb);
@@ -625,7 +625,7 @@ static int is_inbody_header(const struct mailinfo *mi,
625625
{
626626
int i;
627627
const char *val;
628-
for (i = 0; header[i]; i++)
628+
for (i = 0; i < ARRAY_SIZE(header); i++)
629629
if (!mi->s_hdr_data[i] && skip_header(line, header[i], &val))
630630
return 1;
631631
return 0;
@@ -772,7 +772,7 @@ static int check_inbody_header(struct mailinfo *mi, const struct strbuf *line)
772772
return is_format_patch_separator(line->buf + 1, line->len - 1);
773773
if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {
774774
int i;
775-
for (i = 0; header[i]; i++)
775+
for (i = 0; i < ARRAY_SIZE(header); i++)
776776
if (!strcmp("Subject", header[i])) {
777777
handle_header(&mi->s_hdr_data[i], line);
778778
return 1;
@@ -824,7 +824,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
824824
* We may have already read "secondary headers"; purge
825825
* them to give ourselves a clean restart.
826826
*/
827-
for (i = 0; header[i]; i++) {
827+
for (i = 0; i < ARRAY_SIZE(header); i++) {
828828
if (mi->s_hdr_data[i])
829829
strbuf_release(mi->s_hdr_data[i]);
830830
FREE_AND_NULL(mi->s_hdr_data[i]);
@@ -1155,7 +1155,7 @@ static void handle_info(struct mailinfo *mi)
11551155
struct strbuf *hdr;
11561156
int i;
11571157

1158-
for (i = 0; header[i]; i++) {
1158+
for (i = 0; i < ARRAY_SIZE(header); i++) {
11591159
/* only print inbody headers if we output a patch file */
11601160
if (mi->patch_lines && mi->s_hdr_data[i])
11611161
hdr = mi->s_hdr_data[i];

0 commit comments

Comments
 (0)