* [PATCH] fast-import.c: stricter strtoul check, silence compiler warning
@ 2008-12-21 1:28 René Scharfe
0 siblings, 0 replies; only message in thread
From: René Scharfe @ 2008-12-21 1:28 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano
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>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2008-12-21 1:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-21 1:28 [PATCH] fast-import.c: stricter strtoul check, silence compiler warning René Scharfe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox