Skip to content

Commit 1aeb7e7

Browse files
dschogitster
authored andcommitted
parse_timestamp(): specify explicitly where we parse timestamps
Currently, Git's source code represents all timestamps as `unsigned long`. In preparation for using a more appropriate data type, let's introduce a symbol `parse_timestamp` (currently being defined to `strtoul`) where appropriate, so that we can later easily switch to, say, use `strtoull()` instead. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent efac8ac commit 1aeb7e7

File tree

13 files changed

+20
-18
lines changed

13 files changed

+20
-18
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
882882
char *end;
883883

884884
errno = 0;
885-
timestamp = strtoul(str, &end, 10);
885+
timestamp = parse_timestamp(str, &end, 10);
886886
if (errno)
887887
return error(_("invalid timestamp"));
888888

builtin/receive-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ static const char *check_nonce(const char *buf, size_t len)
534534
retval = NONCE_BAD;
535535
goto leave;
536536
}
537-
stamp = strtoul(nonce, &bohmac, 10);
537+
stamp = parse_timestamp(nonce, &bohmac, 10);
538538
if (bohmac == nonce || bohmac[0] != '-') {
539539
retval = NONCE_BAD;
540540
goto leave;
@@ -552,7 +552,7 @@ static const char *check_nonce(const char *buf, size_t len)
552552
* would mean it was issued by another server with its clock
553553
* skewed in the future.
554554
*/
555-
ostamp = strtoul(push_cert_nonce, NULL, 10);
555+
ostamp = parse_timestamp(push_cert_nonce, NULL, 10);
556556
nonce_stamp_slop = (long)ostamp - (long)stamp;
557557

558558
if (nonce_stamp_slop_limit &&

bundle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
227227
line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
228228
if (!line++)
229229
goto out;
230-
date = strtoul(line, NULL, 10);
230+
date = parse_timestamp(line, NULL, 10);
231231
result = (revs->max_age == -1 || revs->max_age < date) &&
232232
(revs->min_age == -1 || revs->min_age > date);
233233
out:

commit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
8989
/* nada */;
9090
if (buf >= tail)
9191
return 0;
92-
/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
93-
return strtoul(dateptr, NULL, 10);
92+
/* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
93+
return parse_timestamp(dateptr, NULL, 10);
9494
}
9595

9696
static struct commit_graft **commit_graft;
@@ -607,7 +607,7 @@ static void record_author_date(struct author_date_slab *author_date,
607607
!ident.date_begin || !ident.date_end)
608608
goto fail_exit; /* malformed "author" line */
609609

610-
date = strtoul(ident.date_begin, &date_end, 10);
610+
date = parse_timestamp(ident.date_begin, &date_end, 10);
611611
if (date_end != ident.date_end)
612612
goto fail_exit; /* malformed date */
613613
*(author_date_slab_at(author_date, commit)) = date;

date.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
510510
char *end;
511511
unsigned long num;
512512

513-
num = strtoul(date, &end, 10);
513+
num = parse_timestamp(date, &end, 10);
514514

515515
/*
516516
* Seconds since 1970? We trigger on that for any numbers with
@@ -658,7 +658,7 @@ static int match_object_header_date(const char *date, unsigned long *timestamp,
658658

659659
if (*date < '0' || '9' < *date)
660660
return -1;
661-
stamp = strtoul(date, &end, 10);
661+
stamp = parse_timestamp(date, &end, 10);
662662
if (*end != ' ' || stamp == ULONG_MAX || (end[1] != '+' && end[1] != '-'))
663663
return -1;
664664
date = end + 2;
@@ -1066,7 +1066,7 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num,
10661066
time_t now)
10671067
{
10681068
char *end;
1069-
unsigned long number = strtoul(date, &end, 10);
1069+
unsigned long number = parse_timestamp(date, &end, 10);
10701070

10711071
switch (*end) {
10721072
case ':':

fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static int fsck_ident(const char **ident, struct object *obj, struct fsck_option
691691
p++;
692692
if (*p == '0' && p[1] != ' ')
693693
return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
694-
if (date_overflows(strtoul(p, &end, 10)))
694+
if (date_overflows(parse_timestamp(p, &end, 10)))
695695
return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
696696
if ((end == p || *end != ' '))
697697
return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");

git-compat-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ extern char *gitdirname(char *);
319319
#define PRIo32 "o"
320320
#endif
321321

322+
#define parse_timestamp strtoul
323+
322324
#ifndef PATH_SEP
323325
#define PATH_SEP ':'
324326
#endif

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ const char *show_ident_date(const struct ident_split *ident,
409409
long tz = 0;
410410

411411
if (ident->date_begin && ident->date_end)
412-
date = strtoul(ident->date_begin, NULL, 10);
412+
date = parse_timestamp(ident->date_begin, NULL, 10);
413413
if (date_overflows(date))
414414
date = 0;
415415
else {

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
868868

869869
if (!eoemail)
870870
goto bad;
871-
timestamp = strtoul(eoemail + 2, &zone, 10);
871+
timestamp = parse_timestamp(eoemail + 2, &zone, 10);
872872
if (timestamp == ULONG_MAX)
873873
goto bad;
874874
tz = strtol(zone, NULL, 10);

refs/files-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3247,7 +3247,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
32473247
parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
32483248
!(email_end = strchr(p, '>')) ||
32493249
email_end[1] != ' ' ||
3250-
!(timestamp = strtoul(email_end + 2, &message, 10)) ||
3250+
!(timestamp = parse_timestamp(email_end + 2, &message, 10)) ||
32513251
!message || message[0] != ' ' ||
32523252
(message[1] != '+' && message[1] != '-') ||
32533253
!isdigit(message[2]) || !isdigit(message[3]) ||

0 commit comments

Comments
 (0)