Skip to content

Commit 69e24de

Browse files
committed
mailinfo: do not let handle_boundary() touch global "line" directly
This function has a single caller, and called with the global "line" holding the multi-part boundary line the caller saw while processing the e-mail body. The function then goes into a loop to process each line of the input, and fills the same global "line" variable from the input as it needs to read more lines to process the multi-part headers. Let the caller explicitly pass a pointer to this global "line" variable as an argument, and have the function itself use that strbuf throughout, instead of referring to the global "line" itself. There still is a helper function that this function calls that still touches the global directly; it will be updated as the series progresses. Signed-off-by: Junio C Hamano <[email protected]>
1 parent fde00d5 commit 69e24de

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin/mailinfo.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -795,14 +795,14 @@ static int find_boundary(void)
795795
return 0;
796796
}
797797

798-
static int handle_boundary(int *filter_stage, int *header_stage)
798+
static int handle_boundary(struct strbuf *line, int *filter_stage, int *header_stage)
799799
{
800800
struct strbuf newline = STRBUF_INIT;
801801

802802
strbuf_addch(&newline, '\n');
803803
again:
804-
if (line.len >= (*content_top)->len + 2 &&
805-
!memcmp(line.buf + (*content_top)->len, "--", 2)) {
804+
if (line->len >= (*content_top)->len + 2 &&
805+
!memcmp(line->buf + (*content_top)->len, "--", 2)) {
806806
/* we hit an end boundary */
807807
/* pop the current boundary off the stack */
808808
strbuf_release(*content_top);
@@ -831,14 +831,14 @@ static int handle_boundary(int *filter_stage, int *header_stage)
831831
strbuf_reset(&charset);
832832

833833
/* slurp in this section's info */
834-
while (read_one_header_line(&line, fin))
835-
check_header(&line, p_hdr_data, 0);
834+
while (read_one_header_line(line, fin))
835+
check_header(line, p_hdr_data, 0);
836836

837837
strbuf_release(&newline);
838838
/* replenish line */
839-
if (strbuf_getline(&line, fin, '\n'))
839+
if (strbuf_getline(line, fin, '\n'))
840840
return 0;
841-
strbuf_addch(&line, '\n');
841+
strbuf_addch(line, '\n');
842842
return 1;
843843
}
844844

@@ -862,7 +862,7 @@ static void handle_body(struct strbuf *line)
862862
handle_filter(&prev, &filter_stage, &header_stage);
863863
strbuf_reset(&prev);
864864
}
865-
if (!handle_boundary(&filter_stage, &header_stage))
865+
if (!handle_boundary(line, &filter_stage, &header_stage))
866866
goto handle_body_out;
867867
}
868868

0 commit comments

Comments
 (0)