bug269-setjmp.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */ ;
  15. /* Test case for Bugzilla # 269 */
  16. #include <stdio.h>
  17. #include <setjmp.h>
  18. #include <stdlib.h>
  19. jmp_buf buf1;
  20. jmp_buf buf2;
  21. int *p;
  22. int n_x = 6;
  23. static int g_counter = 0;
  24. int
  25. f (void)
  26. {
  27. static int counter = 0;
  28. static int way_point1 = 3;
  29. static int way_point2 = 2;
  30. int lose = 0;
  31. if (setjmp (buf1) != 101)
  32. {
  33. int a[n_x]; /* reallocate stack space */
  34. g_counter++;
  35. p = &a[0];
  36. if (g_counter < 5)
  37. longjmp (buf1, 2);
  38. else if (g_counter == 5)
  39. longjmp (buf1, 101);
  40. else
  41. {
  42. _setjmp (buf2);
  43. _longjmp (buf1, 101);
  44. }
  45. }
  46. way_point1--;
  47. if (counter == 0)
  48. {
  49. counter++;
  50. {
  51. int a[n_x]; /* reallocate stack space */
  52. g_counter++;
  53. p = &a[0];
  54. if (g_counter < 5)
  55. longjmp (buf1, 2);
  56. else if (g_counter == 5)
  57. longjmp (buf1, 101);
  58. else
  59. {
  60. _setjmp (buf2);
  61. _longjmp (buf1, 101);
  62. }
  63. }
  64. }
  65. way_point2--;
  66. if (counter == 1)
  67. {
  68. counter++;
  69. longjmp (buf2, 2);
  70. }
  71. lose = !(way_point1 == 0 && way_point2 == 0
  72. && g_counter == 6 && counter == 2);
  73. return lose;
  74. }
  75. static int
  76. do_test (void)
  77. {
  78. int lose;
  79. lose = f ();
  80. if (lose)
  81. puts ("Test FAILED!");
  82. else
  83. puts ("Test succeeded!");
  84. return lose ? EXIT_FAILURE : EXIT_SUCCESS;
  85. }
  86. #define TEST_FUNCTION do_test ()
  87. #include "../test-skeleton.c"