-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[libc++][format] Discard contents since null-terminator in character arrays in formatting #116571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
96f2f4c
[libc++][format] Decay character arrays in formatting
frederick-vs-ja e051073
Address review comments
frederick-vs-ja ca72e26
Merge branch 'main' into format-decay-array
frederick-vs-ja 2c10c77
Address review comments
frederick-vs-ja 9d74f16
Merge branch 'main' into format-decay-array
frederick-vs-ja f7777e8
Fix type of `__pzero`
frederick-vs-ja 36af43f
Merge branch 'main' into format-decay-array
frederick-vs-ja 0dd86fd
Merge branch 'main' into format-decay-array
frederick-vs-ja 9a1911a
Hardening and test
frederick-vs-ja 7f71c5b
Test non-strictly null terminated arrays
frederick-vs-ja 624d001
Merge branch 'main' into format-decay-array
frederick-vs-ja 76225c7
Fix `formatter.char_array.pass.cpp`
frederick-vs-ja abccac0
Merge branch 'main' into format-decay-array
frederick-vs-ja 4838f50
Fix up `formatter.char_array.pass.cpp` with `wchar_t`
frederick-vs-ja 67e4a01
Merge branch 'main' into format-decay-array
frederick-vs-ja 4b2f7ee
Fix and harden `<__format/formatter_string.h>`
frederick-vs-ja 749b552
Merge branch 'main' into format-decay-array
frederick-vs-ja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
libcxx/test/libcxx/utilities/format/format.arguments/format.arg/assert.array.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <format> | ||
|
||
// Formatting non-null-terminated character arrays. | ||
|
||
// REQUIRES: std-at-least-c++20, has-unix-headers, libcpp-hardening-mode={{extensive|debug}} | ||
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing | ||
|
||
#include <format> | ||
|
||
#include "check_assertion.h" | ||
|
||
int main(int, char**) { | ||
{ | ||
const char non_null_terminated[3]{'1', '2', '3'}; | ||
TEST_LIBCPP_ASSERT_FAILURE(std::format("{}", non_null_terminated), "formatting a non-null-terminated array"); | ||
} | ||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS | ||
{ | ||
const wchar_t non_null_terminated[3]{L'1', L'2', L'3'}; | ||
TEST_LIBCPP_ASSERT_FAILURE(std::format(L"{}", non_null_terminated), "formatting a non-null-terminated array"); | ||
} | ||
#endif | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these really useful? They are only used twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I roughly remember that the old form was related to something weird (possibly for the
T[0]
extension), so I added the new internal trait.