From 6ab49225e63ddabe5ee4f16ec28dc8b7c7b499fc Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 13:01:09 -0400 Subject: [PATCH 01/26] Add more c string functions to cstring --- stl/inc/cstring | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stl/inc/cstring b/stl/inc/cstring index a0140aa307c..776bc56751e 100644 --- a/stl/inc/cstring +++ b/stl/inc/cstring @@ -23,22 +23,28 @@ _STD_BEGIN #pragma warning(disable : 4995) // name was marked as #pragma deprecated using _CSTD size_t; +using _CSTD memccpy; using _CSTD memchr; using _CSTD memcmp; using _CSTD memcpy; using _CSTD memmove; using _CSTD memset; +using _CSTD memrchr; using _CSTD strcat; using _CSTD strchr; using _CSTD strcmp; using _CSTD strcoll; using _CSTD strcpy; using _CSTD strcspn; +using _CSTD strdup; using _CSTD strerror; using _CSTD strlen; using _CSTD strncat; using _CSTD strncmp; using _CSTD strncpy; +using _CSTD strndup; +using _CSTD strnlen; +using _CSTD strnstr; using _CSTD strpbrk; using _CSTD strrchr; using _CSTD strspn; From 73fe5670af556809b8bb703d51b862ef55d9f80b Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 13:36:49 -0400 Subject: [PATCH 02/26] Remove not standard c function --- stl/inc/cstring | 1 - 1 file changed, 1 deletion(-) diff --git a/stl/inc/cstring b/stl/inc/cstring index 776bc56751e..ca737121788 100644 --- a/stl/inc/cstring +++ b/stl/inc/cstring @@ -29,7 +29,6 @@ using _CSTD memcmp; using _CSTD memcpy; using _CSTD memmove; using _CSTD memset; -using _CSTD memrchr; using _CSTD strcat; using _CSTD strchr; using _CSTD strcmp; From dad12b0d542955c5265a60fdb647f6cad05140c8 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 13:42:39 -0400 Subject: [PATCH 03/26] Remove more c string functions not in the c string library --- stl/inc/cstring | 2 -- 1 file changed, 2 deletions(-) diff --git a/stl/inc/cstring b/stl/inc/cstring index ca737121788..253d416cf53 100644 --- a/stl/inc/cstring +++ b/stl/inc/cstring @@ -41,9 +41,7 @@ using _CSTD strlen; using _CSTD strncat; using _CSTD strncmp; using _CSTD strncpy; -using _CSTD strndup; using _CSTD strnlen; -using _CSTD strnstr; using _CSTD strpbrk; using _CSTD strrchr; using _CSTD strspn; From 6c750feb34230422ef890fa6571ce60f7681d55a Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 14:14:06 -0400 Subject: [PATCH 04/26] Have it pass --- tests/libcxx/expected_results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index 1ca004839ba..39dec687186 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -420,7 +420,7 @@ std/thread/futures/futures.promise/set_value_const.pass.cpp FAIL # GH-757 : Too many enabled hash specializations std/strings/basic.string.hash/char_type_hash.fail.cpp FAIL -std/strings/string.view/string.view.hash/char_type.hash.fail.cpp FAIL +std/strings/string.view/string.view.hash/char_type.hash.fail.cpp PASS # GH-784 : aligned_storage has incorrect alignment defaults std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp FAIL From 5a9f39f46bfd9df8d20ddedd10b6f40ba2517faf Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 15:16:14 -0400 Subject: [PATCH 05/26] Update expected_results.txt --- tests/libcxx/expected_results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index 39dec687186..aadbf91736a 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -420,7 +420,7 @@ std/thread/futures/futures.promise/set_value_const.pass.cpp FAIL # GH-757 : Too many enabled hash specializations std/strings/basic.string.hash/char_type_hash.fail.cpp FAIL -std/strings/string.view/string.view.hash/char_type.hash.fail.cpp PASS +std/strings/string.view/string.view.hash/char_type.hash.pass.cpp PASS # GH-784 : aligned_storage has incorrect alignment defaults std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp FAIL From 37df6d6e48db8fa91e1b5ba313a4b8f2b1733585 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 15:33:18 -0400 Subject: [PATCH 06/26] Update expected_results.txt --- tests/libcxx/expected_results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index aadbf91736a..1ca004839ba 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -420,7 +420,7 @@ std/thread/futures/futures.promise/set_value_const.pass.cpp FAIL # GH-757 : Too many enabled hash specializations std/strings/basic.string.hash/char_type_hash.fail.cpp FAIL -std/strings/string.view/string.view.hash/char_type.hash.pass.cpp PASS +std/strings/string.view/string.view.hash/char_type.hash.fail.cpp FAIL # GH-784 : aligned_storage has incorrect alignment defaults std/utilities/meta/meta.trans/meta.trans.other/aligned_storage.pass.cpp FAIL From f9d49734bc95d4da25a9c038b4eb7f248a64fafd Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 16:54:30 -0400 Subject: [PATCH 07/26] Remove bad names --- stl/inc/cstring | 2 -- 1 file changed, 2 deletions(-) diff --git a/stl/inc/cstring b/stl/inc/cstring index 253d416cf53..2a39db49b46 100644 --- a/stl/inc/cstring +++ b/stl/inc/cstring @@ -23,7 +23,6 @@ _STD_BEGIN #pragma warning(disable : 4995) // name was marked as #pragma deprecated using _CSTD size_t; -using _CSTD memccpy; using _CSTD memchr; using _CSTD memcmp; using _CSTD memcpy; @@ -35,7 +34,6 @@ using _CSTD strcmp; using _CSTD strcoll; using _CSTD strcpy; using _CSTD strcspn; -using _CSTD strdup; using _CSTD strerror; using _CSTD strlen; using _CSTD strncat; From c48fdb6e46b02a156729850807d3fb1f7e93b699 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 17:03:39 -0400 Subject: [PATCH 08/26] Add strnlen to tests --- tests/tr1/tests/cstring/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/tr1/tests/cstring/test.cpp b/tests/tr1/tests/cstring/test.cpp index c142ad6cedc..469d411f2b5 100644 --- a/tests/tr1/tests/cstring/test.cpp +++ b/tests/tr1/tests/cstring/test.cpp @@ -66,6 +66,10 @@ void test_cpp() { // test C++ header if (n < sizeof(s) - 1) { // buffer big enough, check results CHECK_INT(STDx strxfrm(s, &abcde[0], n + 1), n); CHECK_INT(STDx strlen(s), n); + + CHECK_INT(STDx strnlen(s, n + 1), n); + CHECK_INT(STDx strnlen(s, n - 1), n - 1); + CHECK_INT(STDx strnlen(s, n), n); } // test overloads From 3b7ad2579c2063c649b477bb0cbd6757dd99fd25 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 17:06:57 -0400 Subject: [PATCH 09/26] Fix formatting --- tests/tr1/tests/cstring/test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/tr1/tests/cstring/test.cpp b/tests/tr1/tests/cstring/test.cpp index 469d411f2b5..03187384c1c 100644 --- a/tests/tr1/tests/cstring/test.cpp +++ b/tests/tr1/tests/cstring/test.cpp @@ -65,8 +65,7 @@ void test_cpp() { // test C++ header n = STDx strxfrm((char*) nullptr, &abcde[0], 0); if (n < sizeof(s) - 1) { // buffer big enough, check results CHECK_INT(STDx strxfrm(s, &abcde[0], n + 1), n); - CHECK_INT(STDx strlen(s), n); - + CHECK_INT(STDx strlen(s), n); CHECK_INT(STDx strnlen(s, n + 1), n); CHECK_INT(STDx strnlen(s, n - 1), n - 1); CHECK_INT(STDx strnlen(s, n), n); From d4df5e46466433473b52ce1c97d8f7a2d29dd84f Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 17:09:35 -0400 Subject: [PATCH 10/26] Fix formatting From adcf708bb1d6e5ecad409b75392568629bb9f60e Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sat, 10 Jul 2021 17:19:06 -0400 Subject: [PATCH 11/26] Format fix --- tests/tr1/tests/cstring/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tr1/tests/cstring/test.cpp b/tests/tr1/tests/cstring/test.cpp index 03187384c1c..0f01cae40cd 100644 --- a/tests/tr1/tests/cstring/test.cpp +++ b/tests/tr1/tests/cstring/test.cpp @@ -65,7 +65,7 @@ void test_cpp() { // test C++ header n = STDx strxfrm((char*) nullptr, &abcde[0], 0); if (n < sizeof(s) - 1) { // buffer big enough, check results CHECK_INT(STDx strxfrm(s, &abcde[0], n + 1), n); - CHECK_INT(STDx strlen(s), n); + CHECK_INT(STDx strlen(s), n); CHECK_INT(STDx strnlen(s, n + 1), n); CHECK_INT(STDx strnlen(s, n - 1), n - 1); CHECK_INT(STDx strnlen(s, n), n); From d78bbbb5d935fc5b41b1f85669d4ea0f558024cf Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Sun, 11 Jul 2021 15:21:14 -0400 Subject: [PATCH 12/26] Use for string --- stl/inc/xstring | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 3613f07e03a..4054189ed78 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -142,9 +142,8 @@ struct _Char_traits { // properties of a string or stream element _NODISCARD static _CONSTEXPR17 size_t length(_In_z_ const _Elem* _First) noexcept /* strengthened */ { // find length of null-terminated sequence - size_t _Count = 0; - while (*_First != _Elem()) { - ++_Count; + size_t _Count; + for (_Count = 0; *_First != _Elem(); ++_Count) { ++_First; } From 94cf8c958bcc0990ad2f29afa48134cedf4e0375 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Sun, 11 Jul 2021 16:53:18 -0400 Subject: [PATCH 13/26] Optimize xstring some more (#2) --- stl/inc/xstring | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 4054189ed78..8a9016bc31c 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -110,8 +110,8 @@ struct _Char_traits { // properties of a string or stream element _First1[_Idx] = _First2[_Idx]; } } else { - for (size_t _Idx = 0; _Idx < _Count; ++_Idx) { - _First1[_Count - 1 - _Idx] = _First2[_Count - 1 - _Idx]; + for (size_t _Idx = _Count; _Idx > 0; --_Idx) { + _First1[_Idx - 1] = _First2[_Idx - 1]; } } From 815cb9a46bf7e916e9da2cd4176993d70b59f89d Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Sun, 11 Jul 2021 16:59:59 -0400 Subject: [PATCH 14/26] =?UTF-8?q?Don=E2=80=99t=20bother=20with=20strnlen?= =?UTF-8?q?=20if=20the=20width=20is=20less=20than=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stl/inc/ostream | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index 61766bf311e..44bf044e610 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -652,8 +652,8 @@ template class _CRTIMP2_PURE_IMPORT basic_ostream basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, const char* _Val) { // insert NTBS ios_base::iostate _State = ios_base::goodbit; - streamsize _Count = static_cast(_CSTD strlen(_Val)); - streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() <= _Count ? 0 : _Ostr.width() - _Count; + streamsize _Count; + streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() == (_Count = static_cast(_CSTD strnlen(_Val, static_cast(_Ostr.width()))) ? 0 : _Ostr.width() - _Count; const typename basic_ostream<_Elem, _Traits>::sentry _Ok(_Ostr); if (!_Ok) { From 08c2194452faaf5b2143d8eaef99e1d48841a9d3 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Sun, 11 Jul 2021 17:03:57 -0400 Subject: [PATCH 15/26] Fix formatting --- stl/inc/ostream | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index 44bf044e610..be04a0ca677 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -653,7 +653,7 @@ template basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, const char* _Val) { // insert NTBS ios_base::iostate _State = ios_base::goodbit; streamsize _Count; - streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() == (_Count = static_cast(_CSTD strnlen(_Val, static_cast(_Ostr.width()))) ? 0 : _Ostr.width() - _Count; + streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() == (_Count = static_cast(_CSTD strnlen(_Val, static_cast(_Ostr.width()))) ? 0 : _Ostr.width() - _Count; const typename basic_ostream<_Elem, _Traits>::sentry _Ok(_Ostr); if (!_Ok) { From bf7343378bd2dfef29eba135d243a674200455bc Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Sun, 11 Jul 2021 17:09:27 -0400 Subject: [PATCH 16/26] Fix error --- stl/inc/ostream | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index be04a0ca677..61766bf311e 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -652,8 +652,8 @@ template class _CRTIMP2_PURE_IMPORT basic_ostream basic_ostream<_Elem, _Traits>& operator<<(basic_ostream<_Elem, _Traits>& _Ostr, const char* _Val) { // insert NTBS ios_base::iostate _State = ios_base::goodbit; - streamsize _Count; - streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() == (_Count = static_cast(_CSTD strnlen(_Val, static_cast(_Ostr.width()))) ? 0 : _Ostr.width() - _Count; + streamsize _Count = static_cast(_CSTD strlen(_Val)); + streamsize _Pad = _Ostr.width() <= 0 || _Ostr.width() <= _Count ? 0 : _Ostr.width() - _Count; const typename basic_ostream<_Elem, _Traits>::sentry _Ok(_Ostr); if (!_Ok) { From e59157359d8246489954d7b23f1d4e58c5a8a6ff Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Sun, 11 Jul 2021 17:49:27 -0400 Subject: [PATCH 17/26] =?UTF-8?q?Fix=20for=20loop=20that=20SHOULDN?= =?UTF-8?q?=E2=80=99T=20cause=20tests=20to=20fail=20but=20for=20some=20rea?= =?UTF-8?q?son=20MSVC=20fails=20despite=20it=20being=20the=20same=20but=20?= =?UTF-8?q?with=20a=20different=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stl/inc/xstring | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 8a9016bc31c..47f0cef8755 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -142,8 +142,8 @@ struct _Char_traits { // properties of a string or stream element _NODISCARD static _CONSTEXPR17 size_t length(_In_z_ const _Elem* _First) noexcept /* strengthened */ { // find length of null-terminated sequence - size_t _Count; - for (_Count = 0; *_First != _Elem(); ++_Count) { + size_t _Count = 0; + for (; *_First != _Elem(); ++_Count) { ++_First; } From 9d102657b6cd737d95cc49af6599c85b65c605b3 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Mon, 12 Jul 2021 10:29:22 -0400 Subject: [PATCH 18/26] Rearrange variables --- stl/inc/xstring | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 47f0cef8755..f708c715264 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -99,7 +99,7 @@ struct _Char_traits { // properties of a string or stream element bool _Loop_forward = true; for (const _Elem* _Src = _First2; _Src != _First2 + _Count; ++_Src) { - if (_First1 == _Src) { + if (_Src == _First1) { _Loop_forward = false; break; } @@ -143,8 +143,8 @@ struct _Char_traits { // properties of a string or stream element _NODISCARD static _CONSTEXPR17 size_t length(_In_z_ const _Elem* _First) noexcept /* strengthened */ { // find length of null-terminated sequence size_t _Count = 0; - for (; *_First != _Elem(); ++_Count) { - ++_First; + for (; *_First != _Elem(); ++_First) { + ++_Count; } return _Count; From 946ebece876c2d73d941c7cda6b8595afb661e3e Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Mon, 12 Jul 2021 10:38:56 -0400 Subject: [PATCH 19/26] Update xstring --- stl/inc/xstring | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index f708c715264..d7979152257 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -133,7 +133,7 @@ struct _Char_traits { // properties of a string or stream element // compare [_First1, _First1 + _Count) with [_First2, ...) for (; 0 < _Count; --_Count, ++_First1, ++_First2) { if (*_First1 != *_First2) { - return *_First1 < *_First2 ? -1 : +1; + return *_First1 > *_First2 ? +1: -1; } } @@ -592,14 +592,14 @@ constexpr int _Traits_compare(_In_reads_(_Left_size) const _Traits_ptr_t<_Traits return _Ans; } - if (_Left_size < _Right_size) { - return -1; - } - if (_Left_size > _Right_size) { return 1; } + if (_Left_size < _Right_size) { + return -1; + } + return 0; } From 0f7dbd70acea55043ee8ebdc933df2b08c07d927 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Mon, 12 Jul 2021 10:58:39 -0400 Subject: [PATCH 20/26] Revert some changes --- stl/inc/xstring | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index d7979152257..9cc2ff97cef 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -133,7 +133,7 @@ struct _Char_traits { // properties of a string or stream element // compare [_First1, _First1 + _Count) with [_First2, ...) for (; 0 < _Count; --_Count, ++_First1, ++_First2) { if (*_First1 != *_First2) { - return *_First1 > *_First2 ? +1: -1; + return *_First1 < *_First2 ? -1: +1; } } @@ -592,14 +592,14 @@ constexpr int _Traits_compare(_In_reads_(_Left_size) const _Traits_ptr_t<_Traits return _Ans; } - if (_Left_size > _Right_size) { - return 1; - } - if (_Left_size < _Right_size) { return -1; } + if (_Left_size > _Right_size) { + return 1; + } + return 0; } From aa79edb0ce7d6deaa80c40a1c571b92ddb0dc6c6 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Mon, 12 Jul 2021 11:06:48 -0400 Subject: [PATCH 21/26] Update xstring --- stl/inc/xstring | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index 9cc2ff97cef..eb375796c0f 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -99,7 +99,7 @@ struct _Char_traits { // properties of a string or stream element bool _Loop_forward = true; for (const _Elem* _Src = _First2; _Src != _First2 + _Count; ++_Src) { - if (_Src == _First1) { + if (_First1 == _Src) { _Loop_forward = false; break; } @@ -133,7 +133,7 @@ struct _Char_traits { // properties of a string or stream element // compare [_First1, _First1 + _Count) with [_First2, ...) for (; 0 < _Count; --_Count, ++_First1, ++_First2) { if (*_First1 != *_First2) { - return *_First1 < *_First2 ? -1: +1; + return *_First1 < *_First2 ? -1 : +1; } } From 1ae1fe68e8f8e3be6b64b43426fc15aa69c2a03a Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Mon, 12 Jul 2021 11:07:21 -0400 Subject: [PATCH 22/26] Create xstring From 05d516e3b4b7e60ba269c4db4ccff9d67ed3a29d Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Mon, 12 Jul 2021 11:08:47 -0400 Subject: [PATCH 23/26] Update xstring --- stl/inc/xstring | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index eb375796c0f..f7802508b47 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -143,8 +143,9 @@ struct _Char_traits { // properties of a string or stream element _NODISCARD static _CONSTEXPR17 size_t length(_In_z_ const _Elem* _First) noexcept /* strengthened */ { // find length of null-terminated sequence size_t _Count = 0; - for (; *_First != _Elem(); ++_First) { + while (*_First != _Elem()) { ++_Count; + ++_First; } return _Count; From 7f244e496d71968fdb51b3e2b08dc78721e11cf1 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Tue, 13 Jul 2021 14:32:06 -0400 Subject: [PATCH 24/26] Remove strnlen --- stl/inc/cstring | 1 - 1 file changed, 1 deletion(-) diff --git a/stl/inc/cstring b/stl/inc/cstring index 2a39db49b46..a0140aa307c 100644 --- a/stl/inc/cstring +++ b/stl/inc/cstring @@ -39,7 +39,6 @@ using _CSTD strlen; using _CSTD strncat; using _CSTD strncmp; using _CSTD strncpy; -using _CSTD strnlen; using _CSTD strpbrk; using _CSTD strrchr; using _CSTD strspn; From f60010d247ed51032d3cdf3d5a28328c17de4762 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Tue, 13 Jul 2021 14:32:40 -0400 Subject: [PATCH 25/26] Remove strnlen --- tests/tr1/tests/cstring/test.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/tr1/tests/cstring/test.cpp b/tests/tr1/tests/cstring/test.cpp index 0f01cae40cd..c142ad6cedc 100644 --- a/tests/tr1/tests/cstring/test.cpp +++ b/tests/tr1/tests/cstring/test.cpp @@ -66,9 +66,6 @@ void test_cpp() { // test C++ header if (n < sizeof(s) - 1) { // buffer big enough, check results CHECK_INT(STDx strxfrm(s, &abcde[0], n + 1), n); CHECK_INT(STDx strlen(s), n); - CHECK_INT(STDx strnlen(s, n + 1), n); - CHECK_INT(STDx strnlen(s, n - 1), n - 1); - CHECK_INT(STDx strnlen(s, n), n); } // test overloads From 07faf1b8e79de92551524856586935e03365e785 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Wed, 14 Jul 2021 18:09:32 -0400 Subject: [PATCH 26/26] Using != universally for unsigned variables is much better Gives the code a more consistent feel --- stl/inc/xstring | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/xstring b/stl/inc/xstring index f7802508b47..3f47238a69a 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -54,7 +54,7 @@ struct _Char_traits { // properties of a string or stream element #ifdef __cpp_lib_is_constant_evaluated if (_STD is_constant_evaluated()) { // pre: [_First1, _First1 + _Count) and [_First2, _First2 + _Count) do not overlap; see LWG-3085 - for (size_t _Idx = 0; _Idx < _Count; ++_Idx) { + for (size_t _Idx = 0; _Idx != _Count; ++_Idx) { _First1[_Idx] = _First2[_Idx]; } @@ -106,11 +106,11 @@ struct _Char_traits { // properties of a string or stream element } if (_Loop_forward) { - for (size_t _Idx = 0; _Idx < _Count; ++_Idx) { + for (size_t _Idx = 0; _Idx != _Count; ++_Idx) { _First1[_Idx] = _First2[_Idx]; } } else { - for (size_t _Idx = _Count; _Idx > 0; --_Idx) { + for (size_t _Idx = _Count; _Idx != 0; --_Idx) { _First1[_Idx - 1] = _First2[_Idx - 1]; } }