Date: Fri, 6 Feb 2015 08:27:04 -0800 From: "Simon J. Gerraty" <sjg@juniper.net> To: Poul-Henning Kamp <phk@phk.freebsd.dk> Cc: "freebsd-arch@freebsd.org" <freebsd-arch@freebsd.org>, Anuranjan Shukla <anshukla@juniper.net>, sjg@juniper.net Subject: Re: Buggy sbspace() on 64bit builds? Message-ID: <2705.1423240024@chaos> In-Reply-To: <37282.1423208201@critter.freebsd.dk> References: <D0F95E21.2489D%anshukla@juniper.net> <37282.1423208201@critter.freebsd.dk>
next in thread | previous in thread | raw e-mail | index | archive | help
Poul-Henning Kamp <phk@phk.freebsd.dk> wrote:
> >Any thoughts on what a fix should be for this?
>
> size_t or intptr_t ?
I don't think so, the bug lies in the fact that on 64bit long is much
bigger than the uint's that are being manipulated.
Using a result object the same size works.
Here's a simple demo of the problem:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
uint a, b;
long r1;
int r2;
a = 1;
b = 2;
r1 = a - b;
r2 = a - b;
printf("r1=%ld\nr2=%d\n", r1, r2);
exit(0);
}
32bit version outputs:
r1=-1
r2=-1
64bit version outputs:
r1=4294967295
r2=-1
the r1 value is obviously not what is expected by the caller.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2705.1423240024>
