[libcxx-commits] [libcxx] 8242768 - [libc++][format] Use a helper constant.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Apr 7 10:25:36 PDT 2022
Author: Mark de Wever
Date: 2022-04-07T19:25:13+02:00
New Revision: 82427685ea3732665286d5b1c8a1424b1f96164e
URL: https://github.com/llvm/llvm-project/commit/82427685ea3732665286d5b1c8a1424b1f96164e
DIFF: https://github.com/llvm/llvm-project/commit/82427685ea3732665286d5b1c8a1424b1f96164e.diff
LOG: [libc++][format] Use a helper constant.
The code accidentally uses a hard-coded value. Use a constant to make
sure the same value is used at both places.
Added:
Modified:
libcxx/include/__format/formatter_pointer.h
Removed:
################################################################################
diff --git a/libcxx/include/__format/formatter_pointer.h b/libcxx/include/__format/formatter_pointer.h
index aa4fc3398d096..539992fe866f1 100644
--- a/libcxx/include/__format/formatter_pointer.h
+++ b/libcxx/include/__format/formatter_pointer.h
@@ -46,10 +46,12 @@ class _LIBCPP_TEMPLATE_VIS __formatter_pointer : public __parser_pointer<_CharT>
// but that code isn't public. Making that code public requires some
// refactoring.
// TODO FMT Remove code duplication.
- char __buffer[2 + 2 * sizeof(uintptr_t)];
+ constexpr size_t __max_hex_digits = 2 * sizeof(uintptr_t);
+ char __buffer[2 + __max_hex_digits];
__buffer[0] = '0';
__buffer[1] = 'x';
- char* __last = __to_buffer(__buffer + 2, _VSTD::end(__buffer), reinterpret_cast<uintptr_t>(__ptr), 16);
+ char* __last =
+ __to_buffer(__buffer + 2, _VSTD::end(__buffer), reinterpret_cast<uintptr_t>(__ptr), __max_hex_digits);
unsigned __size = __last - __buffer;
if (__size >= this->__width)
More information about the libcxx-commits
mailing list