Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Jul 2001 09:07:01 -0700
From:      "David O'Brien" <obrien@FreeBSD.org>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org, Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Subject:   Re: cvs commit: src/usr.sbin/newsyslog Makefile newsyslog.c
Message-ID:  <20010731090701.A70277@dragon.nuxi.com>
In-Reply-To: <XFMail.010731084518.jhb@FreeBSD.org>; from jhb@FreeBSD.org on Tue, Jul 31, 2001 at 08:45:18AM -0700
References:  <20010730163112.A83693@dragon.nuxi.com> <XFMail.010731084518.jhb@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

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 <stdio.h>
#include <stdlib.h>

> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010731090701.A70277>