From 7853451b01c8535e31f0d7130dceb5117db4af1c Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Sun, 14 Jul 2019 22:47:33 +0200 Subject: [PATCH] Added buffer size check while populating it. --- dll/steam_inventory.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dll/steam_inventory.h b/dll/steam_inventory.h index 23708c2..5ebce4c 100644 --- a/dll/steam_inventory.h +++ b/dll/steam_inventory.h @@ -144,17 +144,23 @@ bool GetResultItems( SteamInventoryResult_t resultHandle, if (pOutItemsArray != nullptr) { - for (auto& i : items) + uint32 max_items = *punOutItemsArraySize; + // We end if we reached the end of items or the end of buffer + for( auto i = items.begin(); i != items.end() && max_items; ++i, --max_items ) { - pOutItemsArray->m_iDefinition = i.first; - pOutItemsArray->m_itemId = i.first; + pOutItemsArray->m_iDefinition = i->first; + pOutItemsArray->m_itemId = i->first; pOutItemsArray->m_unQuantity = 1; pOutItemsArray->m_unFlags = k_ESteamItemNoTrade; ++pOutItemsArray; } + *punOutItemsArraySize = std::min(*punOutItemsArraySize, static_cast(items.size())); + } + else if (punOutItemsArraySize != nullptr) + { + *punOutItemsArraySize = items.size(); } - if (punOutItemsArraySize)* punOutItemsArraySize = items.size(); PRINT_DEBUG("GetResultItems good\n"); return true; }