Blame setjmp/bug269-setjmp.c

Packit 6c4009
/* Copyright (C) 2004-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/* Test case for Bugzilla # 269 */
Packit 6c4009
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <setjmp.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
Packit 6c4009
jmp_buf buf1;
Packit 6c4009
jmp_buf buf2;
Packit 6c4009
int *p;
Packit 6c4009
int n_x = 6;
Packit 6c4009
Packit 6c4009
static int g_counter = 0;
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
f (void)
Packit 6c4009
{
Packit 6c4009
  static int counter = 0;
Packit 6c4009
  static int way_point1 = 3;
Packit 6c4009
  static int way_point2 = 2;
Packit 6c4009
  int lose = 0;
Packit 6c4009
Packit 6c4009
  if (setjmp (buf1) != 101)
Packit 6c4009
    {
Packit 6c4009
      int a[n_x];		/* reallocate stack space */
Packit 6c4009
      g_counter++;
Packit 6c4009
      p = &a[0];
Packit 6c4009
      if (g_counter < 5)
Packit 6c4009
	longjmp (buf1, 2);
Packit 6c4009
      else if (g_counter == 5)
Packit 6c4009
	longjmp (buf1, 101);
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  _setjmp (buf2);
Packit 6c4009
	  _longjmp (buf1, 101);
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  way_point1--;
Packit 6c4009
Packit 6c4009
  if (counter == 0)
Packit 6c4009
    {
Packit 6c4009
      counter++;
Packit 6c4009
      {
Packit 6c4009
	int a[n_x];		/* reallocate stack space */
Packit 6c4009
	g_counter++;
Packit 6c4009
	p = &a[0];
Packit 6c4009
	if (g_counter < 5)
Packit 6c4009
	  longjmp (buf1, 2);
Packit 6c4009
	else if (g_counter == 5)
Packit 6c4009
	  longjmp (buf1, 101);
Packit 6c4009
	else
Packit 6c4009
	  {
Packit 6c4009
	    _setjmp (buf2);
Packit 6c4009
	    _longjmp (buf1, 101);
Packit 6c4009
	  }
Packit 6c4009
      }
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  way_point2--;
Packit 6c4009
Packit 6c4009
  if (counter == 1)
Packit 6c4009
    {
Packit 6c4009
      counter++;
Packit 6c4009
      longjmp (buf2, 2);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  lose = !(way_point1 == 0 && way_point2 == 0
Packit 6c4009
	   && g_counter == 6 && counter == 2);
Packit 6c4009
Packit 6c4009
  return lose;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  int lose;
Packit 6c4009
Packit 6c4009
  lose = f ();
Packit 6c4009
Packit 6c4009
  if (lose)
Packit 6c4009
    puts ("Test FAILED!");
Packit 6c4009
  else
Packit 6c4009
    puts ("Test succeeded!");
Packit 6c4009
Packit 6c4009
  return lose ? EXIT_FAILURE : EXIT_SUCCESS;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"