Skip to content

Commit 7555c7e

Browse files
QrczakMKcopybara-github
authored andcommitted
Fix incorrect nullability annotation of absl::Cord::InlineRep::set_data().
It is called with `(nullptr, 0)` by `absl::Cord` constructor from `absl::string_view(nullptr, 0)`. The implementation works for `(nullptr, 0)`. PiperOrigin-RevId: 802213857 Change-Id: Ibb9b9dae620262ebee8aa3347c4177e7a3da52c0
1 parent d5ccaa2 commit 7555c7e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

absl/strings/cord.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ static CordRep* absl_nonnull CordRepFromString(std::string&& src) {
161161
// --------------------------------------------------------------------
162162
// Cord::InlineRep functions
163163

164-
inline void Cord::InlineRep::set_data(const char* absl_nonnull data, size_t n) {
164+
inline void Cord::InlineRep::set_data(const char* absl_nullable data,
165+
size_t n) {
165166
static_assert(kMaxInline == 15, "set_data is hard-coded for a length of 15");
167+
assert(data != nullptr || n == 0);
166168
data_.set_inline_data(data, n);
167169
}
168170

absl/strings/cord.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ class Cord {
921921
// Returns nullptr if holding pointer
922922
const char* absl_nullable data() const;
923923
// Discards pointer, if any
924-
void set_data(const char* absl_nonnull data, size_t n);
924+
void set_data(const char* absl_nullable data, size_t n);
925925
char* absl_nonnull set_data(size_t n); // Write data to the result
926926
// Returns nullptr if holding bytes
927927
absl::cord_internal::CordRep* absl_nullable tree() const;

0 commit comments

Comments
 (0)