git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] fast-import.c: stricter strtoul check, silence compiler warning

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Dec 21, 2008, 01:28 UTC
Message-ID
<1229822928.31765.30.camel@ubuntu.ubuntu-domain>

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
Message 1 of 1 in “fast-import.c: stricter strtoul check, silence compiler warning”
  1. fast-import.c: stricter strtoul check, silence compiler warningRené Scharfe, Dec 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.