From owner-cvs-all Tue Jul 31 9: 7:11 2001 Delivered-To: cvs-all@freebsd.org Received: from dragon.nuxi.com (trang.nuxi.com [206.40.252.115]) by hub.freebsd.org (Postfix) with ESMTP id E134637B403; Tue, 31 Jul 2001 09:07:01 -0700 (PDT) (envelope-from obrien@NUXI.com) Received: (from obrien@localhost) by dragon.nuxi.com (8.11.4/8.11.1) id f6VG71Q70562; Tue, 31 Jul 2001 09:07:01 -0700 (PDT) (envelope-from obrien) Date: Tue, 31 Jul 2001 09:07:01 -0700 From: "David O'Brien" To: John Baldwin Cc: cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org, Garrett Wollman Subject: Re: cvs commit: src/usr.sbin/newsyslog Makefile newsyslog.c Message-ID: <20010731090701.A70277@dragon.nuxi.com> Reply-To: obrien@FreeBSD.org References: <20010730163112.A83693@dragon.nuxi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from jhb@FreeBSD.org on Tue, Jul 31, 2001 at 08:45:18AM -0700 X-Operating-System: FreeBSD 5.0-CURRENT Organization: The NUXI BSD group X-Pgp-Rsa-Fingerprint: B7 4D 3E E9 11 39 5F A3 90 76 5D 69 58 D9 98 7A X-Pgp-Rsa-Keyid: 1024/34F9F9D5 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 On Tue, Jul 31, 2001 at 08:45:18AM -0700, John Baldwin wrote: > It only returns ULONG_MAX if the original value would overflow. > > strtoul() of '-4' will return -4: Lets fix this program first: #include #include > const char *s = "-4"; > > int > main() > { > int x; unsigned long x; > x = strtoul(s, NULL, 0); > printf("s = \"%s\", x = %d\n", s, x); printf("s = \"%s\", x = %lu\n", s, x); > return 0; > } > s = "-4", x = -4 Now you get the correct answer: > Granted, when x is unsigned, you get: > > s = "-4", x = 4294967292 And unsigned *is* what the strtoul is defined to return. With you assigning the return of strtoul() to something else, and printing it as something else than %ul; all bets are off. -- -- David (obrien@FreeBSD.org) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message