Skip to content

Commit fde00d5

Browse files
committed
mailinfo: do not let handle_body() touch global "line" directly
This function has a single caller, and called with the global "line" holding the first line of the e-mail body after the caller finished processing the e-mail headers. The function then goes into a loop to process each line of the input, starting from what was given by its caller, and fills the same global "line" variable from the input as it needs to process more lines. 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 are helper functions that this function calls that still touch the global directly; they will be updated as the series progresses. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 269e239 commit fde00d5

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
@@ -842,7 +842,7 @@ static int handle_boundary(int *filter_stage, int *header_stage)
842842
return 1;
843843
}
844844

845-
static void handle_body(void)
845+
static void handle_body(struct strbuf *line)
846846
{
847847
struct strbuf prev = STRBUF_INIT;
848848
int filter_stage = 0;
@@ -856,7 +856,7 @@ static void handle_body(void)
856856

857857
do {
858858
/* process any boundary lines */
859-
if (*content_top && is_multipart_boundary(&line)) {
859+
if (*content_top && is_multipart_boundary(line)) {
860860
/* flush any leftover */
861861
if (prev.len) {
862862
handle_filter(&prev, &filter_stage, &header_stage);
@@ -867,7 +867,7 @@ static void handle_body(void)
867867
}
868868

869869
/* Unwrap transfer encoding */
870-
decode_transfer_encoding(&line);
870+
decode_transfer_encoding(line);
871871

872872
switch (transfer_encoding) {
873873
case TE_BASE64:
@@ -876,15 +876,15 @@ static void handle_body(void)
876876
struct strbuf **lines, **it, *sb;
877877

878878
/* Prepend any previous partial lines */
879-
strbuf_insert(&line, 0, prev.buf, prev.len);
879+
strbuf_insert(line, 0, prev.buf, prev.len);
880880
strbuf_reset(&prev);
881881

882882
/*
883883
* This is a decoded line that may contain
884884
* multiple new lines. Pass only one chunk
885885
* at a time to handle_filter()
886886
*/
887-
lines = strbuf_split(&line, '\n');
887+
lines = strbuf_split(line, '\n');
888888
for (it = lines; (sb = *it); it++) {
889889
if (*(it + 1) == NULL) /* The last line */
890890
if (sb->buf[sb->len - 1] != '\n') {
@@ -902,10 +902,10 @@ static void handle_body(void)
902902
break;
903903
}
904904
default:
905-
handle_filter(&line, &filter_stage, &header_stage);
905+
handle_filter(line, &filter_stage, &header_stage);
906906
}
907907

908-
} while (!strbuf_getwholeline(&line, fin, '\n'));
908+
} while (!strbuf_getwholeline(line, fin, '\n'));
909909

910910
handle_body_out:
911911
strbuf_release(&prev);
@@ -991,7 +991,7 @@ static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch)
991991
while (read_one_header_line(&line, fin))
992992
check_header(&line, p_hdr_data, 1);
993993

994-
handle_body();
994+
handle_body(&line);
995995
fclose(patchfile);
996996

997997
handle_info();

0 commit comments

Comments
 (0)