segv in memcpy on alpha

=?koi8-r?Q?=E7=CF=CC=D5=C2=C5=D7_=E9=CC=D8=D1_=EE?=. gin@mo.msk.ru
Thu Oct 21 06:19:00 GMT 1999


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)
{
}


More information about the Gcc-bugs mailing list