[libcxx-commits] [libcxx] [libc++] Fix possible out of range access in bitset::to_ullong implementation (PR #121348)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 2 14:22:48 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 4922350407127607a9e78fc6d19f3f6278b1e46b f85d6e7af5fe0db6855a6182cc37102b0ac4ecfe --extensions  -- libcxx/include/bitset
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/include/bitset b/libcxx/include/bitset
index ebebea4e83..9d0728c9a1 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -375,7 +375,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
 __bitset<_N_words, _Size>::to_ulong(true_type, true_type) const {
   unsigned long __r       = __first_[0];
   const size_t __ul_words = sizeof(unsigned long) / sizeof(__storage_type);
-  const size_t __n  = _N_words < __ul_words ? _N_words : __ul_words;
+  const size_t __n        = _N_words < __ul_words ? _N_words : __ul_words;
   for (size_t __i = 1; __i < __n; ++__i)
     __r |= static_cast<unsigned long>(__first_[__i]) << (__bits_per_word * __i);
   return __r;
@@ -411,7 +411,7 @@ __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
   _LIBCPP_DIAGNOSTIC_PUSH
   _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
   const size_t __ull_words = sizeof(unsigned long long) / sizeof(__storage_type);
-  const size_t __n   = _N_words < __ull_words ? _N_words : __ull_words;
+  const size_t __n         = _N_words < __ull_words ? _N_words : __ull_words;
   for (size_t __i = 1; __i < __n; ++__i)
     __r |= static_cast<unsigned long long>(__first_[__i]) << (__bits_per_word * __i);
   _LIBCPP_DIAGNOSTIC_POP

``````````

</details>


https://github.com/llvm/llvm-project/pull/121348


More information about the libcxx-commits mailing list