As an optimization, we maintain a default instance of a string in memory, and messages with uninitialized fields will be constructed with a pointer to this default string object. The destructor should clear the field only when it is "set" to a nondefault object. If `ClearNonDefaultToEmpty()` is ever called on a default string... - It will result in undefined behaviour. Most likely, it results in overwriting an object in memory (which is already full of zeros) with another bunch of zeros. - It's quite bad for a number of reasons: 1. It can confuse TSAN. 2. It blocks us from moving the default instance of the string into the `.data` section. Having the default instance of the string live in read-only memory would be beneficial for memory safety. It would play well with hugepages. It would also eliminate some runtime cost of instantiating the default instance of the string. This change adds a debug-fail so that users don't call this function "unsafely". PiperOrigin-RevId: 684569674pull/18762/head
parent
0d7fd35086
commit
6c9c12c8a1
1 changed files with 1 additions and 0 deletions
Loading…
Reference in new issue