[PATCH] fast-import.c: stricter strtoul check, silence compiler warning
From: René Scharfe <hidden>
Date: 2016-06-15 22:45:48
Subsystem:
the rest · Maintainer:
Linus Torvalds
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 <redacted> --- I don't really like the first part, as we're ignoring the return value anyway, even if we store it in the variable "date", so this is quite useless. But better to have a bit more useless code than to see these equally useless warnings on every build. Turning them off completely is not a good idea, since some of them resulted in useful fixes (see 47d32af2, 304dcf26, 7be77de2). fast-import.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 171d178..a6bce66 100644
--- a/fast-import.c
+++ b/fast-import.c@@ -1748,18 +1748,21 @@ static int validate_raw_date(const char *src, char *result, int maxlen) { const char *orig_src = src; char *endp, sign; + unsigned long date; - strtoul(src, &endp, 10); - if (endp == src || *endp != ' ') + errno = 0; + + date = strtoul(src, &endp, 10); + if (errno || endp == src || *endp != ' ') return -1; src = endp + 1; if (*src != '-' && *src != '+') return -1; sign = *src; - strtoul(src + 1, &endp, 10); - if (endp == src || *endp || (endp - orig_src) >= maxlen) + date = strtoul(src + 1, &endp, 10); + if (errno || endp == src || *endp || (endp - orig_src) >= maxlen) return -1; strcpy(result, orig_src);
--
1.6.1.rc3.52.g589372