From f34658c4859121149139acb68303ab6f31813beb Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 27 Feb 2025 00:08:49 +0100 Subject: [PATCH] count the null byte when enumerating strings --- client/xr/details/enumerate.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/xr/details/enumerate.h b/client/xr/details/enumerate.h index 6a40ac11..b0d50d14 100644 --- a/client/xr/details/enumerate.h +++ b/client/xr/details/enumerate.h @@ -82,12 +82,18 @@ template void enumerate(F f, std::conditional_t, std::string, std::vector> & data, Args &&... args) { uint32_t count; - XrResult result = f(std::forward(args)..., data.size(), &count, reinterpret_cast::base *>(data.data())); + uint32_t capacity = data.size(); + // For strings, add the null byte as capacity + if (std::is_same_v and capacity) + capacity++; + XrResult result = f(std::forward(args)..., capacity, &count, reinterpret_cast::base *>(data.data())); if (result == XR_ERROR_SIZE_INSUFFICIENT or (data.empty() and XR_SUCCEEDED(result))) { if constexpr (structure_type != XR_TYPE_UNKNOWN) data.resize(count, T{.type = structure_type}); + else if constexpr (std::is_same_v) + data.resize(count - 1); // count includes the null terminator else data.resize(count); return enumerate(f, data, std::forward(args)...);