public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-7918] libstdc++: Add test for illegal pointer arithmetic in format [PR111102]
Date: Wed, 27 Sep 2023 16:19:29 +0000 (GMT)	[thread overview]
Message-ID: <20230927161929.9866638582BD@sourceware.org> (raw)

https://gcc.gnu.org/g:9853ad876bd3d9d4685126466f74402e567664b3

commit r13-7918-g9853ad876bd3d9d4685126466f74402e567664b3
Author: Paul Dreik <gccpatches@pauldreik.se>
Date:   Thu Aug 24 11:43:43 2023 +0100

    libstdc++: Add test for illegal pointer arithmetic in format [PR111102]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/111102
            * testsuite/std/format/string.cc: Check wide character format
            strings with out-of-range widths.
    
    (cherry picked from commit 7564fe98657ad5ede34bd08f5279778fa8698865)

Diff:
---
 libstdc++-v3/testsuite/std/format/string.cc | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/libstdc++-v3/testsuite/std/format/string.cc b/libstdc++-v3/testsuite/std/format/string.cc
index fef55b9bcd9..a472f8d588c 100644
--- a/libstdc++-v3/testsuite/std/format/string.cc
+++ b/libstdc++-v3/testsuite/std/format/string.cc
@@ -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

                 reply	other threads:[~2023-09-27 16:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230927161929.9866638582BD@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).