bug-strncat1.c 771 B

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