bug-asctime_r.c 610 B

1234567891011121314151617181920212223242526272829303132
  1. #include <errno.h>
  2. #include <limits.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5. static int
  6. do_test (void)
  7. {
  8. int result = 0;
  9. time_t t = time (NULL);
  10. struct tm *tp = localtime (&t);
  11. tp->tm_year = 10000 - 1900;
  12. char buf[1000];
  13. errno = 0;
  14. buf[26] = '\xff';
  15. char *s = asctime_r (tp, buf);
  16. if (s != NULL || errno != EOVERFLOW)
  17. {
  18. puts ("asctime_r did not fail correctly");
  19. result = 1;
  20. }
  21. if (buf[26] != '\xff')
  22. {
  23. puts ("asctime_r overwrote 27th byte in buffer");
  24. result = 1;
  25. }
  26. return result;
  27. }
  28. #define TEST_FUNCTION do_test ()
  29. #include "../test-skeleton.c"