Skip to content

Commit 95b1763

Browse files
derekmaurocopybara-github
authored andcommitted
Add a DCHECK that ArenaStringPtr::Set(char*, Arena*) is not called with
a null char* argument. This is already undefined behavior since the argument is immediately used to construct a string_view, and passing a null argument to the single-arg string_view constructor is undefined behavior. Adding the check will prevent introduction of new bugs when using standard library implementations that do not detect this case. PiperOrigin-RevId: 787178436
1 parent 0b31c2a commit 95b1763

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

‎src/google/protobuf/arenastring.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ inline void ArenaStringPtr::InitAllocated(std::string* str, Arena* arena) {
462462
}
463463

464464
inline void ArenaStringPtr::Set(const char* s, Arena* arena) {
465+
ABSL_DCHECK(s != nullptr);
465466
Set(absl::string_view{s}, arena);
466467
}
467468

0 commit comments

Comments
 (0)