Skip to content

Commit e467dc1

Browse files
dschogitster
authored andcommitted
ref-filter: avoid using unsigned long for catch-all data type
In its `atom_value` struct, the ref-filter source code wants to store different values in a field called `ul` (for `unsigned long`), e.g. timestamps. However, as we are about to switch the data type of timestamps away from `unsigned long` (because it may be 32-bit even when `time_t` is 64-bit), that data type is not large enough. Simply change that field to use `uintmax_t` instead. This patch is a bit larger than the mere change of the data type because the field's name was tied to its data type, which has been fixed at the same time. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a2c2f8 commit e467dc1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

ref-filter.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ struct ref_formatting_state {
351351
struct atom_value {
352352
const char *s;
353353
void (*handler)(struct atom_value *atomv, struct ref_formatting_state *state);
354-
unsigned long ul; /* used for sorting when not FIELD_STR */
354+
uintmax_t value; /* used for sorting when not FIELD_STR */
355355
struct used_atom *atom;
356356
};
357357

@@ -723,7 +723,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
723723
if (!strcmp(name, "objecttype"))
724724
v->s = typename(obj->type);
725725
else if (!strcmp(name, "objectsize")) {
726-
v->ul = sz;
726+
v->value = sz;
727727
v->s = xstrfmt("%lu", sz);
728728
}
729729
else if (deref)
@@ -770,8 +770,8 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
770770
v->s = xstrdup(oid_to_hex(&commit->tree->object.oid));
771771
}
772772
else if (!strcmp(name, "numparent")) {
773-
v->ul = commit_list_count(commit->parents);
774-
v->s = xstrfmt("%lu", v->ul);
773+
v->value = commit_list_count(commit->parents);
774+
v->s = xstrfmt("%lu", (unsigned long)v->value);
775775
}
776776
else if (!strcmp(name, "parent")) {
777777
struct commit_list *parents;
@@ -875,11 +875,11 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
875875
if ((tz == LONG_MIN || tz == LONG_MAX) && errno == ERANGE)
876876
goto bad;
877877
v->s = xstrdup(show_date(timestamp, tz, &date_mode));
878-
v->ul = timestamp;
878+
v->value = timestamp;
879879
return;
880880
bad:
881881
v->s = "";
882-
v->ul = 0;
882+
v->value = 0;
883883
}
884884

885885
/* See grab_values */
@@ -1941,9 +1941,9 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
19411941
else if (cmp_type == FIELD_STR)
19421942
cmp = cmp_fn(va->s, vb->s);
19431943
else {
1944-
if (va->ul < vb->ul)
1944+
if (va->value < vb->value)
19451945
cmp = -1;
1946-
else if (va->ul == vb->ul)
1946+
else if (va->value == vb->value)
19471947
cmp = cmp_fn(a->refname, b->refname);
19481948
else
19491949
cmp = 1;

0 commit comments

Comments
 (0)