[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: apr_off_t is of an ambiguous size.

From: Ben Reser <ben_at_reser.org>
Date: 2004-01-17 23:28:20 CET

On Sat, Jan 17, 2004 at 11:52:43AM -0500, Greg Hudson wrote:
> No, the standard is pretty clear that the compiler is not allowed to
> optimize out operations that could result in an overflow. Otherwise
> optimized code would produce different results than unoptimized code
> with much greater regularity than it does currently, leading to tons of
> debugging headaches.

Okay just thought I'd double check. I've heard the horror stories of
compilers optimizing stuff out that was necessary before. But if you're
comfortable with it I'm okay with it.

> apr_file_seek does modify the offset value, so yes, we need to stuff it
> back into *offset after the call completes.

Yup, I just spaced handling this.

Here's a changed implementation on the basis of your comments:

svn_error_t *
svn_io_file_seek (apr_file_t *file, apr_seek_where_t where,
                  svn_offset_t *offset, apr_pool_t *pool)
{
  /* Because apr_off_t may not be the same size as svn_offset_t we need
   * to do bounds checking to make sure it will fit. The typecasted
   * comparisions do that for us. */
  if ((apr_off_t) *offset == *offset )
    {
      apr_off_t apr_offset = *offset;
      apr_status_t status;

      status = apr_file_seek (file, where, &apr_offset);
    
      if ((svn_offset_t) apr_offset == apr_offset)
        {
          *offset = apr_offset;
          return do_io_file_wrapper_cleanup (file, status,
                                             "set position pointer in",
                                             pool);
        }
    }

    return svn_error_create (SVN_ERR_IO_OFFSET_SIZE, NULL,
                             "Cannot seek file");
}

Any objections to this implementation?

-- 
Ben Reser <ben@reser.org>
http://ben.reser.org
"Conscience is the inner voice which warns us somebody may be looking."
- H.L. Mencken
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Jan 17 23:28:50 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.