ref-filter: drop unused "sz" parameters

Many of our grab_* functions, which parse the object content, take a buf/sz pair of the object bytes. However, the functions which actually parse the buffers (like find_wholine() and find_subpos()) never look at "sz", and instead use functions like strchr() and strchrnul() that assume the result is NUL-terminated. This is OK in practice (and common for Git's parsing code), since we always allocate an extra NUL when loading an object into memory (and likewise, we are OK with stopping parsing if a commit or tag contains an embedded NUL). Let's drop these extra "sz" parameters, as they are misleading about how the functions intend to access the buffer. We can drop from both the functions mentioned above, which in turn lets us drop from their callers, cascading all the way up to the top-level grab_values(). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 14, 2019 at 00:51 UTC 5c326d12524e4395b0ff184123e71738db6c9f65
1 file changed +14 -14
ref-filter.c
+14 -14
@@ -968,7 +968,7 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
968 }
969 }
970
971 -static const char *find_wholine(const char *who, int wholen, const char *buf, unsigned long sz)
971 +static const char *find_wholine(const char *who, int wholen, const char *buf)
972 {
973 const char *eol;
974 while (*buf) {
@@ -1064,7 +1064,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
1064 }
1065
1066 /* See grab_values */
1067 -static void grab_person(const char *who, struct atom_value *val, int deref, void *buf, unsigned long sz)
1067 +static void grab_person(const char *who, struct atom_value *val, int deref, void *buf)
1068 {
1069 int i;
1070 int wholen = strlen(who);
@@ -1085,7 +1085,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
1085 !starts_with(name + wholen, "date"))
1086 continue;
1087 if (!wholine)
1088 - wholine = find_wholine(who, wholen, buf, sz);
1088 + wholine = find_wholine(who, wholen, buf);
1089 if (!wholine)
1090 return; /* no point looking for it */
1091 if (name[wholen] == 0)
@@ -1105,7 +1105,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
1105 if (strcmp(who, "tagger") && strcmp(who, "committer"))
1106 return; /* "author" for commit object is not wanted */
1107 if (!wholine)
1108 - wholine = find_wholine(who, wholen, buf, sz);
1108 + wholine = find_wholine(who, wholen, buf);
1109 if (!wholine)
1110 return;
1111 for (i = 0; i < used_atom_cnt; i++) {
@@ -1123,7 +1123,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
1123 }
1124 }
1125
1126 -static void find_subpos(const char *buf, unsigned long sz,
1126 +static void find_subpos(const char *buf,
1127 const char **sub, unsigned long *sublen,
1128 const char **body, unsigned long *bodylen,
1129 unsigned long *nonsiglen,
@@ -1192,7 +1192,7 @@ static void append_lines(struct strbuf *out, const char *buf, unsigned long size
1192 }
1193
1194 /* See grab_values */
1195 -static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf, unsigned long sz)
1195 +static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
1196 {
1197 int i;
1198 const char *subpos = NULL, *bodypos = NULL, *sigpos = NULL;
@@ -1212,7 +1212,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf,
1212 !starts_with(name, "contents"))
1213 continue;
1214 if (!subpos)
1215 - find_subpos(buf, sz,
1215 + find_subpos(buf,
1216 &subpos, &sublen,
1217 &bodypos, &bodylen, &nonsiglen,
1218 &sigpos, &siglen);
@@ -1265,19 +1265,19 @@ static void fill_missing_values(struct atom_value *val)
1265 * pointed at by the ref itself; otherwise it is the object the
1266 * ref (which is a tag) refers to.
1267 */
1268 -static void grab_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
1268 +static void grab_values(struct atom_value *val, int deref, struct object *obj, void *buf)
1269 {
1270 switch (obj->type) {
1271 case OBJ_TAG:
1272 grab_tag_values(val, deref, obj);
1273 - grab_sub_body_contents(val, deref, buf, sz);
1274 - grab_person("tagger", val, deref, buf, sz);
1273 + grab_sub_body_contents(val, deref, buf);
1274 + grab_person("tagger", val, deref, buf);
1275 break;
1276 case OBJ_COMMIT:
1277 grab_commit_values(val, deref, obj);
1278 - grab_sub_body_contents(val, deref, buf, sz);
1279 - grab_person("author", val, deref, buf, sz);
1280 - grab_person("committer", val, deref, buf, sz);
1278 + grab_sub_body_contents(val, deref, buf);
1279 + grab_person("author", val, deref, buf);
1280 + grab_person("committer", val, deref, buf);
1281 break;
1282 case OBJ_TREE:
1283 /* grab_tree_values(val, deref, obj, buf, sz); */
@@ -1516,7 +1516,7 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
1516 return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"),
1517 oid_to_hex(&oi->oid), ref->refname);
1518 }
1519 - grab_values(ref->value, deref, *obj, oi->content, oi->size);
1519 + grab_values(ref->value, deref, *obj, oi->content);
1520 }
1521
1522 grab_common_values(ref->value, deref, oi);