From: ZheNing Hu <adlternative@xxxxxxxxx> find_subpos() needs to use strlen() to get the length of the object content, but in the caller of find_subpos(): grab_sub_body_contents(), we can already get the length of the object content through data->size. So add a `size_t buf_size` in find_subpos(), and pass data->size to it. This can lead to weak performance optimizations. Signed-off-by: ZheNing Hu <adlternative@xxxxxxxxx> Mentored-by: Christian Couder <christian.couder@xxxxxxxxx> Mentored-by: Hariom Verma <hariom18599@xxxxxxxxx> --- ref-filter.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 3ccb531e073..be4c4405b12 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1346,7 +1346,7 @@ static void grab_person(enum atom_type type, struct atom_value *val, int deref, } } -static void find_subpos(const char *buf, +static void find_subpos(const char *buf, size_t buf_size, const char **sub, size_t *sublen, const char **body, size_t *bodylen, size_t *nonsiglen, @@ -1354,12 +1354,12 @@ static void find_subpos(const char *buf, { struct strbuf payload = STRBUF_INIT; struct strbuf signature = STRBUF_INIT; + const char *begin = buf; 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); + parse_signature(buf, buf_size, &payload, &signature); /* skip past header until we hit empty line */ while (*buf && *buf != '\n') { @@ -1372,7 +1372,7 @@ static void find_subpos(const char *buf, while (*buf == '\n') buf++; *sig = strbuf_detach(&signature, siglen); - sigstart = buf + parse_signed_buffer(buf, strlen(buf)); + sigstart = buf + parse_signed_buffer(buf, buf_size - (buf - begin)); /* subject is first non-empty line */ *sub = buf; @@ -1395,7 +1395,7 @@ static void find_subpos(const char *buf, while (*buf == '\n' || *buf == '\r') buf++; *body = buf; - *bodylen = strlen(buf); + *bodylen = buf_size - (buf - begin); *nonsiglen = sigstart - buf; } @@ -1462,7 +1462,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct exp !starts_with(name, "contents"))) continue; if (!subpos) - find_subpos(buf, + find_subpos(buf, data->size, &subpos, &sublen, &bodypos, &bodylen, &nonsiglen, &sigpos, &siglen); -- gitgitgadget