Don't crash if str is null

Is useful especially when we want to create a string from another message string that might be null.
This commit is contained in:
BogDan Vatra
2016-07-13 21:04:26 +03:00
parent df9990acf5
commit 49c10bc219

View File

@@ -876,7 +876,7 @@ FLATBUFFERS_FINAL_CLASS
/// @param[in] str A const pointer to a `String` struct to add to the buffer.
/// @return Returns the offset in the buffer where the string starts
Offset<String> CreateString(const String *str) {
return CreateString(str->c_str(), str->Length());
return str ? CreateString(str->c_str(), str->Length()) : 0;
}
/// @brief Store a string in the buffer, which can contain any binary data.