nethercote | eb0592d | 2004-11-05 12:02:27 +0000 | [diff] [blame] | 1 | #include <assert.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <sys/poll.h> |
| 4 | |
| 5 | // At one point, poll()'s checking was not done accurately. This test |
| 6 | // exposes this -- previously Memcheck only found one error, now if finds |
| 7 | // two. |
| 8 | |
| 9 | int main(void) |
| 10 | { |
| 11 | // Under-allocate by one byte so we get an addressability error. |
| 12 | struct pollfd* ufds = malloc(2 * sizeof(struct pollfd) - 1); |
| 13 | assert(ufds); |
| 14 | |
| 15 | ufds[0].fd = 0; |
| 16 | ufds[0].events = 0; |
| 17 | //ufds[1].fd = 0; // leave undefined so we get another error. |
| 18 | ufds[1].events = 0; |
| 19 | |
| 20 | // Previously, the bounds-error due to the under-allocation was detected, |
| 21 | // but not the undefined value error due to ufds[1].fd not being defined. |
| 22 | poll(ufds, 2, 200); |
| 23 | |
| 24 | return 0; |
| 25 | } |