Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 Jun 2001 07:52:59 -0700 (PDT)
From:      John Polstra <jdp@polstra.com>
To:        stable@freebsd.org
Cc:        avatar@mmlab.cse.yzu.edu.tw
Subject:   Re: lseek(SEEK_END) then read()... bug of feature?
Message-ID:  <200106281452.f5SEqxf93857@vashon.polstra.com>
In-Reply-To: <Pine.BSF.4.33.0106281339090.72014-100000@www.mmlab.cse.yzu.edu.tw>
References:  <Pine.BSF.4.33.0106281339090.72014-100000@www.mmlab.cse.yzu.edu.tw>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <Pine.BSF.4.33.0106281339090.72014-100000@www.mmlab.cse.yzu.edu.tw>,
Tai-hwa Liang  <avatar@mmlab.cse.yzu.edu.tw> wrote:
> Hi,
> 
> 	Anyone tried lseek() from the end of file then read something
> out? I've tested the attached code on FreeBSD 4-stable. Both of the two
> -stable box(cvsupped on May-02-2001 and Jun-19-2001) prints error
> message(Undefined error: 0) on the first read(); however, the second
> read() worked without any problem....

It is caused by a bug in your program.

> #include <fcntl.h>
> #include <stdio.h>
> #include <unistd.h>
> 
> int
> main()
> {
> 	unsigned int	l = 0;
> 	off_t		offset;
> 	int		ret, fd = open("/kernel", O_RDONLY);
> 
> 	offset = 0 - sizeof(int);

Due to C's type promotion rules, this assigns the value 4294967292
to "offset".  Change it to this:

  	offset = (off_t)0 - sizeof(int);

and your program works fine.

John
-- 
  John Polstra                                               jdp@polstra.com
  John D. Polstra & Co., Inc.                        Seattle, Washington USA
  "Disappointment is a good sign of basic intelligence."  -- Chögyam Trungpa


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




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