Patch for bfd/cache.c - explicit cast to void*

Dave Korn dave.korn.cygwin@googlemail.com
Sun Mar 1 23:56:00 GMT 2009


Tom Tromey wrote:
>>>>>> "Jerker" == Jerker Bäck <jerker.back@telia.com> writes:

  For some reason I'm not seeing a lot of Jerker's posts.  Pardon me for
piggy-backing on your reply, Tom, most of this is addressed to Jerker.

> Jerker> Some compilers refuse to compile the current source and emmits:
> Jerker> error C2036: 'void *' : unknown size 

  Errr... where is there any void* pointer arithmetic going on in the
original?  Does MSVC have addition and casts in the wrong precedence?

> gdb uses -Wpointer-arith when compiled with gcc; perhaps binutils
> ought to do this as well.
> 
> Jerker> +      chunk_nread = cache_bread_1 (abfd, (void*)((file_ptr)buf + nread), chunk_size);
> 
> I think just (char *) buf + nread would be more typical.

  That's how the code already reads currently:

> -chunk_nread = cache_bread_1(abfd, (char*)buf + nread, chunk_size);
> +chunk_nread = cache_bread_1(abfd, (void*)((file_ptr)buf + nread),
>    chunk_size);

  And I couldn't get the current code to warn under MSVC6.1 with this testcase:

--------------------------------------------------------------------------
typedef unsigned long int file_ptr;

static file_ptr
cache_bread_1 (/*struct bfd *abfd, */void *buf, file_ptr nbytes)
{
  return 0;
}

int test (void *buf, file_ptr nread, file_ptr chunk_size)
{
  file_ptr chunk_nread;
  chunk_nread = cache_bread_1 (/*abfd, */(char *) buf + nread, chunk_size);
  return (chunk_nread & 0xffff);
}

int main (int argc, const char **argv)
{
  char buf[20];
  return test (&buf[0], 123, 456);
}
--------------------------------------------------------------------------

when compiled in either C or C++.

  Jerker, could you confirm that you were definitely using clean sources when
you saw this problem originally?  And give somehow steps to reproduce this
problem, or details of the environment you're seeing it in?

    cheers,
      DaveK



More information about the Binutils mailing list