Back to index

glibc  2.9
bug269-setjmp.c
Go to the documentation of this file.
00001 /* Copyright (C) 2004 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */ ;
00018 
00019 /* Test case for Bugzilla # 269 */
00020 
00021 #include <stdio.h>
00022 #include <setjmp.h>
00023 #include <stdlib.h>
00024 
00025 jmp_buf buf1;
00026 jmp_buf buf2;
00027 int *p;
00028 int n_x = 6;
00029 
00030 static int g_counter = 0;
00031 
00032 int
00033 f (void) 
00034 {
00035   static int counter = 0;
00036   static int way_point1 = 3;
00037   static int way_point2 = 2;
00038   int lose = 0;
00039 
00040   if (setjmp (buf1) != 101)
00041     {
00042       int a[n_x];           /* reallocate stack space */
00043       g_counter++;
00044       p = &a[0];
00045       if (g_counter < 5)
00046        longjmp (buf1, 2);
00047       else if (g_counter == 5)
00048        longjmp (buf1, 101);
00049       else
00050        {
00051          _setjmp (buf2);
00052          _longjmp (buf1, 101);
00053        }
00054     }
00055 
00056   way_point1--;
00057 
00058   if (counter == 0)
00059     {
00060       counter++;
00061       {
00062        int a[n_x];          /* reallocate stack space */
00063        g_counter++;
00064        p = &a[0];
00065        if (g_counter < 5)
00066          longjmp (buf1, 2);
00067        else if (g_counter == 5)
00068          longjmp (buf1, 101);
00069        else
00070          {
00071            _setjmp (buf2);
00072            _longjmp (buf1, 101);
00073          }
00074       }
00075     }
00076 
00077   way_point2--;
00078 
00079   if (counter == 1)
00080     {
00081       counter++;
00082       longjmp (buf2, 2);
00083     }
00084 
00085   lose = !(way_point1 == 0 && way_point2 == 0
00086           && g_counter == 6 && counter == 2);
00087 
00088   return lose;
00089 }
00090 
00091 static int
00092 do_test (void)
00093 {
00094   int lose;
00095 
00096   lose = f ();
00097 
00098   if (lose)
00099     puts ("Test FAILED!");
00100   else
00101     puts ("Test succeeded!");
00102 
00103   return lose ? EXIT_FAILURE : EXIT_SUCCESS;
00104 }
00105 
00106 #define TEST_FUNCTION do_test ()
00107 #include "../test-skeleton.c"