@matheusbsbs / matheus-bagliano / commits / c55fae43c4
Fork 0

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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Dec 21, 2008 at 02:28 UTC c55fae43c4e10e2779e4fb7d70d6f6e4a7645a63
1 file changed +7 -4
fast-import.c
+7 -4
@@ -1748,9 +1748,12 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
1748 {
1749 const char *orig_src = src;
1750 char *endp, sign;
1751 + unsigned long date;
1752
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 != ' ')
1757 return -1;
1758
1759 src = endp + 1;
@@ -1758,8 +1761,8 @@ static int validate_raw_date(const char *src, char *result, int maxlen)
1761 return -1;
1762 sign = *src;
1763
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)
1766 return -1;
1767
1768 strcpy(result, orig_src);