]> gcc.gnu.org Git - gcc.git/commitdiff
libstdc++: Add test for illegal pointer arithmetic in format [PR111102]
authorPaul Dreik <gccpatches@pauldreik.se>
Thu, 24 Aug 2023 10:43:43 +0000 (11:43 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 24 Aug 2023 12:44:39 +0000 (13:44 +0100)
libstdc++-v3/ChangeLog:

PR libstdc++/111102
* testsuite/std/format/string.cc: Check wide character format
strings with out-of-range widths.

libstdc++-v3/testsuite/std/format/string.cc

index fef55b9bcd9e0bfe8f961b36ec09437264e005a4..a472f8d588c213c26b7ef79f9c401c3f3634f2fa 100644 (file)
@@ -16,6 +16,18 @@ is_format_string_for(const char* str, Args&&... args)
   }
 }
 
+template<typename... Args>
+bool
+is_format_string_for(const wchar_t* str, Args&&... args)
+{
+  try {
+    (void) std::vformat(str, std::make_wformat_args(args...));
+    return true;
+  } catch (const std::format_error&) {
+    return false;
+  }
+}
+
 void
 test_no_args()
 {
@@ -124,8 +136,11 @@ test_format_spec()
 
   // Maximum integer value supported for widths and precisions is USHRT_MAX.
   VERIFY( is_format_string_for("{:65535}", 1) );
+  VERIFY( is_format_string_for(L"{:65535}", 1) );
   VERIFY( ! is_format_string_for("{:65536}", 1) );
+  VERIFY( ! is_format_string_for(L"{:65536}", 1) );
   VERIFY( ! is_format_string_for("{:9999999}", 1) );
+  VERIFY( ! is_format_string_for(L"{:9999999}", 1) );
 }
 
 void
This page took 0.069735 seconds and 5 git commands to generate.