tst-ldbl-nonnormal-printf.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Test printf with x86-specific non-normal long double value.
  2. Copyright (C) 2020-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <support/check.h>
  18. /* Fill the stack with non-zero values. This makes a crash in
  19. snprintf more likely. */
  20. static void __attribute_optimization_barrier__
  21. fill_stack (void)
  22. {
  23. char buffer[65536];
  24. memset (buffer, 0xc0, sizeof (buffer));
  25. asm ("" ::: "memory");
  26. }
  27. static int
  28. do_test (void)
  29. {
  30. fill_stack ();
  31. long double value;
  32. memcpy (&value, "\x00\x04\x00\x00\x00\x00\x00\x00\x00\x04", 10);
  33. char buf[30];
  34. int ret = snprintf (buf, sizeof (buf), "%Lg", value);
  35. TEST_COMPARE (ret, strlen (buf));
  36. TEST_COMPARE_STRING (buf, "nan");
  37. return 0;
  38. }
  39. #include <support/test-driver.c>