From 55621d1af55be7bf9a2c8e5dcef4368d9a6d4e51 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Mon, 11 Dec 2023 09:07:07 -0800 Subject: Add nullability annotations PiperOrigin-RevId: 589842893 Change-Id: I9657761d1f71c665582406f278c6605f6d382f6d --- absl/strings/charconv.cc | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'absl/strings/charconv.cc') diff --git a/absl/strings/charconv.cc b/absl/strings/charconv.cc index 60b3715c..eda6d506 100644 --- a/absl/strings/charconv.cc +++ b/absl/strings/charconv.cc @@ -23,6 +23,7 @@ #include "absl/base/casts.h" #include "absl/base/config.h" +#include "absl/base/nullability.h" #include "absl/numeric/bits.h" #include "absl/numeric/int128.h" #include "absl/strings/internal/charconv_bigint.h" @@ -119,7 +120,7 @@ struct FloatTraits { // Parsing a smaller N will produce something finite. static constexpr int kEiselLemireMaxExclusiveExp10 = 309; - static double MakeNan(const char* tagp) { + static double MakeNan(absl::Nullable tagp) { #if ABSL_HAVE_BUILTIN(__builtin_nan) // Use __builtin_nan() if available since it has a fix for // https://bugs.llvm.org/show_bug.cgi?id=37778 @@ -192,7 +193,7 @@ struct FloatTraits { static constexpr int kEiselLemireMinInclusiveExp10 = -46 - 18; static constexpr int kEiselLemireMaxExclusiveExp10 = 39; - static float MakeNan(const char* tagp) { + static float MakeNan(absl::Nullable tagp) { #if ABSL_HAVE_BUILTIN(__builtin_nanf) // Use __builtin_nanf() if available since it has a fix for // https://bugs.llvm.org/show_bug.cgi?id=37778 @@ -344,7 +345,7 @@ int NormalizedShiftSize(int mantissa_width, int binary_exponent) { // `value` must be wider than the requested bit width. // // Returns the number of bits shifted. -int TruncateToBitWidth(int bit_width, uint128* value) { +int TruncateToBitWidth(int bit_width, absl::Nonnull value) { const int current_bit_width = BitWidth(*value); const int shift = current_bit_width - bit_width; *value >>= shift; @@ -356,7 +357,7 @@ int TruncateToBitWidth(int bit_width, uint128* value) { // the appropriate double, and returns true. template bool HandleEdgeCase(const strings_internal::ParsedFloat& input, bool negative, - FloatType* value) { + absl::Nonnull value) { if (input.type == strings_internal::FloatType::kNan) { // A bug in both clang < 7 and gcc would cause the compiler to optimize // away the buffer we are building below. Declaring the buffer volatile @@ -405,7 +406,8 @@ bool HandleEdgeCase(const strings_internal::ParsedFloat& input, bool negative, // number is stored in *value. template void EncodeResult(const CalculatedFloat& calculated, bool negative, - absl::from_chars_result* result, FloatType* value) { + absl::Nonnull result, + absl::Nonnull value) { if (calculated.exponent == kOverflow) { result->ec = std::errc::result_out_of_range; *value = negative ? -std::numeric_limits::max() @@ -451,7 +453,7 @@ void EncodeResult(const CalculatedFloat& calculated, bool negative, // Zero and negative values of `shift` are accepted, in which case the word is // shifted left, as necessary. uint64_t ShiftRightAndRound(uint128 value, int shift, bool input_exact, - bool* output_exact) { + absl::Nonnull output_exact) { if (shift <= 0) { *output_exact = input_exact; return static_cast(value << -shift); @@ -685,7 +687,8 @@ CalculatedFloat CalculateFromParsedDecimal( // this function returns false) is both fast and correct. template bool EiselLemire(const strings_internal::ParsedFloat& input, bool negative, - FloatType* value, std::errc* ec) { + absl::Nonnull value, + absl::Nonnull ec) { uint64_t man = input.mantissa; int exp10 = input.exponent; if (exp10 < FloatTraits::kEiselLemireMinInclusiveExp10) { @@ -858,7 +861,8 @@ bool EiselLemire(const strings_internal::ParsedFloat& input, bool negative, } template -from_chars_result FromCharsImpl(const char* first, const char* last, +from_chars_result FromCharsImpl(absl::Nonnull first, + absl::Nonnull last, FloatType& value, chars_format fmt_flags) { from_chars_result result; result.ptr = first; // overwritten on successful parse @@ -944,12 +948,14 @@ from_chars_result FromCharsImpl(const char* first, const char* last, } } // namespace -from_chars_result from_chars(const char* first, const char* last, double& value, +from_chars_result from_chars(absl::Nonnull first, + absl::Nonnull last, double& value, chars_format fmt) { return FromCharsImpl(first, last, value, fmt); } -from_chars_result from_chars(const char* first, const char* last, float& value, +from_chars_result from_chars(absl::Nonnull first, + absl::Nonnull last, float& value, chars_format fmt) { return FromCharsImpl(first, last, value, fmt); } -- cgit v1.2.3