bug269-setjmp.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. /* Test case for Bugzilla # 269 */
  15. #include <stdio.h>
  16. #include <setjmp.h>
  17. #include <stdlib.h>
  18. jmp_buf buf1;
  19. jmp_buf buf2;
  20. int *p;
  21. int n_x = 6;
  22. static int g_counter = 0;
  23. static int
  24. f (void)
  25. {
  26. static int counter = 0;
  27. static int way_point1 = 3;
  28. static int way_point2 = 2;
  29. int lose = 0;
  30. if (setjmp (buf1) != 101)
  31. {
  32. int a[n_x]; /* reallocate stack space */
  33. g_counter++;
  34. p = &a[0];
  35. if (g_counter < 5)
  36. longjmp (buf1, 2);
  37. else if (g_counter == 5)
  38. longjmp (buf1, 101);
  39. else
  40. {
  41. _setjmp (buf2);
  42. _longjmp (buf1, 101);
  43. }
  44. }
  45. way_point1--;
  46. if (counter == 0)
  47. {
  48. counter++;
  49. {
  50. int a[n_x]; /* reallocate stack space */
  51. g_counter++;
  52. p = &a[0];
  53. if (g_counter < 5)
  54. longjmp (buf1, 2);
  55. else if (g_counter == 5)
  56. longjmp (buf1, 101);
  57. else
  58. {
  59. _setjmp (buf2);
  60. _longjmp (buf1, 101);
  61. }
  62. }
  63. }
  64. way_point2--;
  65. if (counter == 1)
  66. {
  67. counter++;
  68. longjmp (buf2, 2);
  69. }
  70. lose = !(way_point1 == 0 && way_point2 == 0
  71. && g_counter == 6 && counter == 2);
  72. return lose;
  73. }
  74. static int
  75. do_test (void)
  76. {
  77. int lose;
  78. lose = f ();
  79. if (lose)
  80. puts ("Test FAILED!");
  81. else
  82. puts ("Test succeeded!");
  83. return lose ? EXIT_FAILURE : EXIT_SUCCESS;
  84. }
  85. #define TEST_FUNCTION do_test ()
  86. #include "../test-skeleton.c"