Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Jul 2001 18:34:31 -0700 (PDT)
From:      Matt Dillon <dillon@earth.backplane.com>
To:        John Baldwin <jhb@FreeBSD.ORG>
Cc:        "David O'Brien" <obrien@FreeBSD.ORG>, 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:  <200108010134.f711YVt21651@earth.backplane.com>
References:   <XFMail.010731084518.jhb@FreeBSD.org>

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

: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 <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/

    strtol() will fail for any value > 2^31, as documented:

#include <stdio.h>

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




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