Skip to content

Commit c55fae4

Browse files
René Scharfegitster
authored andcommitted
fast-import.c: stricter strtoul check, silence compiler warning
Store the return value of strtoul() in order to avoid compiler warnings on Ubuntu 8.10. Also check errno after each call, which is the only way to notice an overflow without making ULONG_MAX an illegal date. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f14825 commit c55fae4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fast-import.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,18 +1748,21 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
17481748
{
17491749
const char *orig_src = src;
17501750
char *endp, sign;
1751+
unsigned long date;
17511752

1752-
strtoul(src, &endp, 10);
1753-
if (endp == src || *endp != ' ')
1753+
errno = 0;
1754+
1755+
date = strtoul(src, &endp, 10);
1756+
if (errno || endp == src || *endp != ' ')
17541757
return -1;
17551758

17561759
src = endp + 1;
17571760
if (*src != '-' && *src != '+')
17581761
return -1;
17591762
sign = *src;
17601763

1761-
strtoul(src + 1, &endp, 10);
1762-
if (endp == src || *endp || (endp - orig_src) >= maxlen)
1764+
date = strtoul(src + 1, &endp, 10);
1765+
if (errno || endp == src || *endp || (endp - orig_src) >= maxlen)
17631766
return -1;
17641767

17651768
strcpy(result, orig_src);

0 commit comments

Comments
 (0)