Beispiel #1
0
int main ()
{
  const char *const s1 = "hello world";
  const char *const s2 = "";
  char dst[64], *d2;
  
  strcpy (dst, s1);
  if (strncat (dst, "", 100) != dst || strcmp (dst, s1))
    abort();
  strcpy (dst, s1);
  if (strncat (dst, s2, 100) != dst || strcmp (dst, s1))
    abort();
  strcpy (dst, s1); d2 = dst;
  if (strncat (++d2, s2, 100) != dst+1 || d2 != dst+1 || strcmp (dst, s1))
    abort();
  strcpy (dst, s1); d2 = dst;
  if (strncat (++d2+5, s2, 100) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
    abort();
  strcpy (dst, s1); d2 = dst;
  if (strncat (++d2+5, s1+11, 100) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
    abort();
  strcpy (dst, s1); d2 = dst;
  if (strncat (++d2+5, s1, 0) != dst+6 || d2 != dst+1 || strcmp (dst, s1))
    abort();
  strcpy (dst, s1); d2 = dst;
  if (strncat (++d2+5, "", ++x) != dst+6 || d2 != dst+1 || x != 124
      || strcmp (dst, s1))
    abort();

  strcpy (dst, s1);
  if (strncat (dst, "foo", 3) != dst || strcmp (dst, "hello worldfoo"))
    abort();
  strcpy (dst, s1);
  if (strncat (dst, "foo", 100) != dst || strcmp (dst, "hello worldfoo"))
    abort();
  strcpy (dst, s1);
  if (strncat (dst, s1, 100) != dst || strcmp (dst, "hello worldhello world"))
    abort();
  strcpy (dst, s1); d2 = dst;
  if (strncat (++d2, s1, 100) != dst+1 || d2 != dst+1
      || strcmp (dst, "hello worldhello world"))
    abort();
  strcpy (dst, s1); d2 = dst;
  if (strncat (++d2+5, s1, 100) != dst+6 || d2 != dst+1
      || strcmp (dst, "hello worldhello world"))
    abort();
  strcpy (dst, s1); d2 = dst;
  if (strncat (++d2+5, s1+5, 100) != dst+6 || d2 != dst+1
      || strcmp (dst, "hello world world"))
    abort();

  /* Test at least one instance of the __builtin_ style.  We do this
     to ensure that it works and that the prototype is correct.  */
  strcpy (dst, s1);
  if (__builtin_strncat (dst, "", 100) != dst || strcmp (dst, s1))
    abort();

  return 0;
}
Beispiel #2
0
__attribute__((noipa)) size_t
foo (char *p, char *q, size_t *r)
{
  size_t n0 = __builtin_strlen (p);
  __builtin_strncat (q, p, n0);		/* { dg-warning "specified bound depends on the length" } */
  size_t n1 = __builtin_strlen (p);
  *r = n0;
  return n1;
}
Beispiel #3
0
int
main ()
{
  char a[8] = "";
  __builtin_strcpy (a, "123");
  size_t n0 = __builtin_strlen (a);
  __builtin_strncat (a + 3, a, n0);	/* { dg-warning "specified bound depends on the length" } */
  size_t n1 = __builtin_strlen (a);
  if (n1 == n0)
    __builtin_abort ();
  a[6] = '7';
  __builtin_strcpy (a, "456");
  size_t n2;
  if (foo (a, a + 3, &n2) != 6 || n2 != 3)
    __builtin_abort ();
  if (__builtin_memcmp (a, "456456\0", sizeof "456456\0"))
    __builtin_abort ();
  return 0;
}
void f(void *d, const void *s, __SIZE_TYPE__ n)
{
  void *t1 = __builtin_memcpy (d, s, n);
  if (t1 == 0)
    __builtin_abort ();

  void *t2 = __builtin_memmove (d, s, n);
  if (t2 == 0)
    __builtin_abort ();

  void *t3 = __builtin_memset (d, 0, n);
  if (t3 == 0)
    __builtin_abort ();

  void *t4 = __builtin_strcpy (d, s);
  if (t4 == 0)
    __builtin_abort ();

  void *t5 = __builtin_strncpy (d, s, n);
  if (t5 == 0)
    __builtin_abort ();

  void *t6 = __builtin_strcat (d, s);
  if (t6 == 0)
    __builtin_abort ();

  void *t7 = __builtin_strncat (d, s, n);
  if (t7 == 0)
    __builtin_abort ();

  void *t8 = __builtin_stpcpy (d, s);
  if (t8 == 0)
    __builtin_abort ();

  void *t9 = __builtin_stpncpy (d, s, n);
  if (t9 == 0)
    __builtin_abort ();
}