OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [va-arg-21.c] - Diff between revs 149 and 154

Only display areas with differences | Details | Blame | View Log

Rev 149 Rev 154
/* Copyright (C) 2000  Free Software Foundation.
/* Copyright (C) 2000  Free Software Foundation.
 
 
   If the argument to va_end() has side effects, test whether side
   If the argument to va_end() has side effects, test whether side
   effects from that argument are honored.
   effects from that argument are honored.
 
 
   Written by Kaveh R. Ghazi, 10/31/2000.  */
   Written by Kaveh R. Ghazi, 10/31/2000.  */
 
 
#include <stdarg.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
 
 
#ifndef __GNUC__
#ifndef __GNUC__
#define __attribute__(x)
#define __attribute__(x)
#endif
#endif
 
 
static void __attribute__ ((__format__ (__printf__, 1, 2)))
static void __attribute__ ((__format__ (__printf__, 1, 2)))
doit (const char *s, ...)
doit (const char *s, ...)
{
{
  va_list *ap_array[3], **ap_ptr = ap_array;
  va_list *ap_array[3], **ap_ptr = ap_array;
 
 
  ap_array[0] = malloc (sizeof(va_list));
  ap_array[0] = malloc (sizeof(va_list));
  ap_array[1] = NULL;
  ap_array[1] = NULL;
  ap_array[2] = malloc (sizeof(va_list));
  ap_array[2] = malloc (sizeof(va_list));
 
 
  va_start (*ap_array[0], s);
  va_start (*ap_array[0], s);
  vprintf (s, **ap_ptr);
  vprintf (s, **ap_ptr);
  /* Increment the va_list pointer once.  */
  /* Increment the va_list pointer once.  */
  va_end (**ap_ptr++);
  va_end (**ap_ptr++);
 
 
  /* Increment the va_list pointer a second time.  */
  /* Increment the va_list pointer a second time.  */
  ap_ptr++;
  ap_ptr++;
 
 
  va_start (*ap_array[2], s);
  va_start (*ap_array[2], s);
  /* If we failed to increment ap_ptr twice, then the parameter passed
  /* If we failed to increment ap_ptr twice, then the parameter passed
     in here will dereference NULL and should cause a crash.  */
     in here will dereference NULL and should cause a crash.  */
  vprintf (s, **ap_ptr);
  vprintf (s, **ap_ptr);
  va_end (**ap_ptr);
  va_end (**ap_ptr);
 
 
  /* Just in case, If *ap_ptr is NULL abort anyway.  */
  /* Just in case, If *ap_ptr is NULL abort anyway.  */
  if (*ap_ptr == 0)
  if (*ap_ptr == 0)
    abort();
    abort();
}
}
 
 
int main()
int main()
{
{
  doit ("%s", "hello world\n");
  doit ("%s", "hello world\n");
  exit (0);
  exit (0);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.