]> git.ipfire.org Git - thirdparty/git.git/blobdiff - ref-filter.c
Merge branch 'ab/detox-gettext-tests'
[thirdparty/git.git] / ref-filter.c
index fd994e18744cebd22e68fd1d969fb0f621d2362e..bade6528ee36e1efd0a28aeedcb5202f7cc7910d 100644 (file)
@@ -1210,12 +1210,20 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
 }
 
 static void find_subpos(const char *buf,
-                       const char **sub, unsigned long *sublen,
-                       const char **body, unsigned long *bodylen,
-                       unsigned long *nonsiglen,
-                       const char **sig, unsigned long *siglen)
+                       const char **sub, size_t *sublen,
+                       const char **body, size_t *bodylen,
+                       size_t *nonsiglen,
+                       const char **sig, size_t *siglen)
 {
+       struct strbuf payload = STRBUF_INIT;
+       struct strbuf signature = STRBUF_INIT;
        const char *eol;
+       const char *end = buf + strlen(buf);
+       const char *sigstart;
+
+       /* parse signature first; we might not even have a subject line */
+       parse_signature(buf, end - buf, &payload, &signature);
+
        /* skip past header until we hit empty line */
        while (*buf && *buf != '\n') {
                eol = strchrnul(buf, '\n');
@@ -1226,16 +1234,14 @@ static void find_subpos(const char *buf,
        /* skip any empty lines */
        while (*buf == '\n')
                buf++;
-
-       /* parse signature first; we might not even have a subject line */
-       *sig = buf + parse_signature(buf, strlen(buf));
-       *siglen = strlen(*sig);
+       *sig = strbuf_detach(&signature, siglen);
+       sigstart = buf + parse_signed_buffer(buf, strlen(buf));
 
        /* subject is first non-empty line */
        *sub = buf;
        /* subject goes to first empty line before signature begins */
        if ((eol = strstr(*sub, "\n\n"))) {
-               eol = eol < *sig ? eol : *sig;
+               eol = eol < sigstart ? eol : sigstart;
        /* check if message uses CRLF */
        } else if (! (eol = strstr(*sub, "\r\n\r\n"))) {
                /* treat whole message as subject */
@@ -1253,7 +1259,7 @@ static void find_subpos(const char *buf,
                buf++;
        *body = buf;
        *bodylen = strlen(buf);
-       *nonsiglen = *sig - buf;
+       *nonsiglen = sigstart - buf;
 }
 
 /*
@@ -1285,12 +1291,13 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
 {
        int i;
        const char *subpos = NULL, *bodypos = NULL, *sigpos = NULL;
-       unsigned long sublen = 0, bodylen = 0, nonsiglen = 0, siglen = 0;
+       size_t sublen = 0, bodylen = 0, nonsiglen = 0, siglen = 0;
 
        for (i = 0; i < used_atom_cnt; i++) {
                struct used_atom *atom = &used_atom[i];
                const char *name = atom->name;
                struct atom_value *v = &val[i];
+
                if (!!deref != (*name == '*'))
                        continue;
                if (deref)
@@ -1322,7 +1329,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
                        v->s = xmemdupz(sigpos, siglen);
                else if (atom->u.contents.option == C_LINES) {
                        struct strbuf s = STRBUF_INIT;
-                       const char *contents_end = bodylen + bodypos - siglen;
+                       const char *contents_end = bodypos + nonsiglen;
 
                        /*  Size is the length of the message after removing the signature */
                        append_lines(&s, subpos, contents_end - subpos, atom->u.contents.nlines);
@@ -1336,7 +1343,9 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
                        v->s = strbuf_detach(&s, NULL);
                } else if (atom->u.contents.option == C_BARE)
                        v->s = xstrdup(subpos);
+
        }
+       free((void *)sigpos);
 }
 
 /*