This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

segv in memcpy on alpha


Version: 2.95.1
Platform: alpha-dec-osf4.0f

/* Compile with gcc -O2.  Program gets SIGSEGV upon first call of
memcpy().  After un#if' ing #if'ed code it runs normally. */

#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<sys/uio.h>

typedef struct iovec iovec_t;

static void f (iovec_t a);

int
main (void)
{
  iovec_t w;

  {
    char x[16];
    unsigned i;

    for (i = 0; i < 8; i++) {
      w.iov_base = (void *) &x[i];
      w.iov_len = 4;
      f (w);
      printf ("memcpy () with offset %u OK\n", i);
    }
  }
  {
    void *p = malloc (4);

    if (p) {
      w.iov_base = p;
      w.iov_len = 4;
      f (w);
      printf ("memcpy () of malloc ()'ed data OK\n");
      free (p);
    }
  }
  return 0;
}

static void g (size_t s);

static void
f (iovec_t w)
{
  unsigned int s;

  if (w.iov_len == sizeof s) {
#if 0
    g (w.iov_len);
#endif /* 0 */
    memcpy ((void *)&s, w.iov_base, w.iov_len);
  }
}

static void
g (size_t s)
{
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]