--- a/io/tst-closefrom.c +++ b/io/tst-closefrom.c @@ -39,7 +39,7 @@ const int maximum_fd = lowfd + NFDS - 1; const int half_fd = lowfd + NFDS / 2; - const int gap = maximum_fd / 4; + const int gap = lowfd + NFDS / 4; /* Close half of the descriptors and check result. */ closefrom (half_fd); @@ -49,7 +49,7 @@ TEST_COMPARE (fcntl (i, F_GETFL), -1); TEST_COMPARE (errno, EBADF); } - for (int i = 0; i < half_fd; i++) + for (int i = lowfd; i < half_fd; i++) TEST_VERIFY (fcntl (i, F_GETFL) > -1); /* Create some gaps, close up to a threshold, and check result. */ @@ -65,7 +65,7 @@ TEST_COMPARE (fcntl (i, F_GETFL), -1); TEST_COMPARE (errno, EBADF); } - for (int i = 0; i < gap; i++) + for (int i = lowfd; i < gap; i++) TEST_VERIFY (fcntl (i, F_GETFL) > -1); /* Close the remmaining but the last one. */ --- a/sysdeps/unix/sysv/linux/tst-close_range.c +++ b/sysdeps/unix/sysv/linux/tst-close_range.c @@ -189,7 +189,7 @@ support_stack_free (&stack); - for (int i = 0; i < NFDS; i++) + for (int i = lowfd; i < lowfd + NFDS; i++) TEST_VERIFY (fcntl (i, F_GETFL) > -1); support_descriptors_check (descrs2); @@ -240,13 +240,13 @@ /* Create some gaps, close up to a threshold, and check result. */ static int gap_close[] = { 57, 78, 81, 82, 84, 90 }; for (int i = 0; i < array_length (gap_close); i++) - xclose (gap_close[i]); + xclose (lowfd + gap_close[i]); TEST_COMPARE (close_range (half_fd + 1, gap_1, CLOSE_RANGE_CLOEXEC), 0); for (int i = half_fd + 1; i < gap_1; i++) { int flags = fcntl (i, F_GETFD); - if (is_in_array (gap_close, array_length (gap_close), i)) + if (is_in_array (gap_close, array_length (gap_close), i - lowfd)) TEST_COMPARE (flags, -1); else {