From owner-cvs-all Tue Jul 31 19:58:47 2001 Delivered-To: cvs-all@freebsd.org Received: from earth.backplane.com (earth.backplane.com [208.161.114.65]) by hub.freebsd.org (Postfix) with ESMTP id 8C01C37B405; Tue, 31 Jul 2001 19:58:39 -0700 (PDT) (envelope-from dillon@earth.backplane.com) Received: (from dillon@localhost) by earth.backplane.com (8.11.4/8.11.2) id f711YVt21651; Tue, 31 Jul 2001 18:34:31 -0700 (PDT) (envelope-from dillon) Date: Tue, 31 Jul 2001 18:34:31 -0700 (PDT) From: Matt Dillon Message-Id: <200108010134.f711YVt21651@earth.backplane.com> To: John Baldwin Cc: "David O'Brien" , cvs-all@FreeBSD.ORG, cvs-committers@FreeBSD.ORG, Garrett Wollman Subject: Re: cvs commit: src/usr.sbin/newsyslog Makefile newsyslog.c References: Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG :s = "-4", x = -4 : :Granted, when x is unsigned, you get: : :s = "-4", x = 4294967292 : :Which will be large enough for the cases assumed here. : :Does go to show that strtol() wouldn't fail in the negative case however as I :thought. Hmm. This means that you probably could just have done :s/strtoul/strtol/ to get rid of the warning. :) : :-- : :John Baldwin -- http://www.FreeBSD.org/~jhb/ strtol() will fail for any value > 2^31, as documented: #include int main(int ac, char **av) { int x; x = strtol("0x80000000", NULL, 0); printf("%08x\n", x); return(0); } earth:/home/dillon> ./x 7fffffff This has an unfortunate result that is far worse then strtoul()'s unfortunate handling of '-' for -0x80000001 through -0xFFFFFFFF. So, in general, I would recommend using strtoul() exclusively and then casting the result to a signed quantity if you wanted a signed result. Personally I prefer to old assembly 'convert the string to an int and just ignore the overflow' method. strtol() has !@#$%@!#$ me up too many times. -Matt To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message