bug-strncat1.c 747 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */
  2. #undef __USE_STRING_INLINES
  3. #define __USE_STRING_INLINES
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <libc-diag.h>
  8. char d[3] = "\0\1\2";
  9. int
  10. main (void)
  11. {
  12. DIAG_PUSH_NEEDS_COMMENT;
  13. #if __GNUC_PREREQ (8, 0)
  14. /* GCC 8 warns about strncat truncating output; this is deliberately
  15. tested here. */
  16. DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation");
  17. #endif
  18. strncat (d, "\5\6", 1);
  19. DIAG_POP_NEEDS_COMMENT;
  20. if (d[0] != '\5')
  21. {
  22. puts ("d[0] != '\\5'");
  23. exit (1);
  24. }
  25. if (d[1] != '\0')
  26. {
  27. puts ("d[1] != '\\0'");
  28. exit (1);
  29. }
  30. if (d[2] != '\2')
  31. {
  32. puts ("d[2] != '\\2'");
  33. exit (1);
  34. }
  35. return 0;
  36. }