Fix: RNA_property_string_get() always returns zero-length string

The variant of `RNA_property_string_get()` that returns a `std::string`
always returned a string with zero length. The issue is that it was only
calling `reserve()`, which ensures an underlying buffer with enough
*capacity*, but does not set the string length. The property's string
value would then be correctly copied to the reserved buffer, but the
string length would remain zero.

This commit fixes the issue by replacing the call to `reserve()` with a
call to `resize()`, which additionally sets the string length.

Pull Request: https://projects.blender.org/blender/blender/pulls/139106
This commit is contained in:
Nathan Vegdahl
2025-05-20 10:33:19 +02:00
committed by Nathan Vegdahl
parent 717fa42e5e
commit 984a2b5298

View File

@@ -3650,7 +3650,10 @@ std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
size_t length = size_t(RNA_property_string_length(ptr, prop));
std::string string_ret{};
string_ret.reserve(length + 1);
/* Note: after `resize()` the underlying buffer is actually at least `length +
* 1` bytes long, because (since C++11) `std::string` guarantees a terminating
* null byte, but that is not considered part of the length. */
string_ret.resize(length);
if (sprop->get) {
sprop->get(ptr, string_ret.data());