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 <gitster@pobox.com>
Junio C Hamano committed
Oct 18, 2015 at 15:40 UTC
69e24defd629eb6641e653b73459f57ab750c58b
1 file changed
+8
-8
builtin/mailinfo.c
+8
-8
@@ -795,14 +795,14 @@ static int find_boundary(void)
795
return 0;
796
}
797
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)
799
{
800
struct strbuf newline = STRBUF_INIT;
801
802
strbuf_addch(&newline, '\n');
803
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)) {
806
/* we hit an end boundary */
807
/* pop the current boundary off the stack */
808
strbuf_release(*content_top);
@@ -831,14 +831,14 @@ again:
831
strbuf_reset(&charset);
832
833
/* 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);
836
837
strbuf_release(&newline);
838
/* replenish line */
839
- if (strbuf_getline(&line, fin, '\n'))
839
+ if (strbuf_getline(line, fin, '\n'))
840
return 0;
841
- strbuf_addch(&line, '\n');
841
+ strbuf_addch(line, '\n');
842
return 1;
843
}
844
@@ -862,7 +862,7 @@ static void handle_body(struct strbuf *line)
862
handle_filter(&prev, &filter_stage, &header_stage);
863
strbuf_reset(&prev);
864
}
865
- if (!handle_boundary(&filter_stage, &header_stage))
865
+ if (!handle_boundary(line, &filter_stage, &header_stage))
866
goto handle_body_out;
867
}
868