{"thread":{"id":"16815","subject":"[PATCH] fast-import.c: stricter strtoul check, silence compiler warning","startedAt":"2008-12-21T01:28:48Z","lastAt":"2008-12-21T01:28:48Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"98468","messageId":"1229822928.31765.30.camel@ubuntu.ubuntu-domain","threadId":"16815","inReplyTo":null,"subject":"[PATCH] fast-import.c: stricter strtoul check, silence compiler warning","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-12-21T01:28:48Z","receivedAt":"2008-12-21T01:28:48Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Store the return value of strtoul() in order to avoid compiler\nwarnings on Ubuntu 8.10.\n\nAlso check errno after each call, which is the only way to notice\nan overflow without making ULONG_MAX an illegal date.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\nI don't really like the first part, as we're ignoring the return\nvalue anyway, even if we store it in the variable \"date\", so this\nis quite useless.  But better to have a bit more useless code\nthan to see these equally useless warnings on every build.\nTurning them off completely is not a good idea, since some of\nthem resulted in useful fixes (see 47d32af2, 304dcf26, 7be77de2).\n\n fast-import.c |   11 +++++++----\n 1 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 171d178..a6bce66 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1748,18 +1748,21 @@ static int validate_raw_date(const char *src, char *result, int maxlen)\n {\n \tconst char *orig_src = src;\n \tchar *endp, sign;\n+\tunsigned long date;\n \n-\tstrtoul(src, &endp, 10);\n-\tif (endp == src || *endp != ' ')\n+\terrno = 0;\n+\n+\tdate = strtoul(src, &endp, 10);\n+\tif (errno || endp == src || *endp != ' ')\n \t\treturn -1;\n \n \tsrc = endp + 1;\n \tif (*src != '-' && *src != '+')\n \t\treturn -1;\n \tsign = *src;\n \n-\tstrtoul(src + 1, &endp, 10);\n-\tif (endp == src || *endp || (endp - orig_src) >= maxlen)\n+\tdate = strtoul(src + 1, &endp, 10);\n+\tif (errno || endp == src || *endp || (endp - orig_src) >= maxlen)\n \t\treturn -1;\n \n \tstrcpy(result, orig_src);\n-- \n1.6.1.rc3.52.g589372\n"}]}